Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright 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 
     31 #include <base/callback_forward.h>
     32 #include <vector>
     33 
     34 #ifndef BTA_GATT_DEBUG
     35 #define BTA_GATT_DEBUG false
     36 #endif
     37 
     38 /*****************************************************************************
     39  *  Constants and data types
     40  ****************************************************************************/
     41 /**************************
     42  *  Common Definitions
     43  **************************/
     44 /* GATT ID */
     45 typedef struct {
     46   bluetooth::Uuid uuid; /* uuid of the attribute */
     47   uint8_t inst_id;      /* instance ID */
     48 } __attribute__((packed)) tBTA_GATT_ID;
     49 
     50 /* Client callback function events */
     51 #define BTA_GATTC_DEREG_EVT 1        /* GATT client deregistered event */
     52 #define BTA_GATTC_OPEN_EVT 2         /* GATTC open request status  event */
     53 #define BTA_GATTC_CLOSE_EVT 5        /* GATTC  close request status event */
     54 #define BTA_GATTC_SEARCH_CMPL_EVT 6  /* GATT discovery complete event */
     55 #define BTA_GATTC_SEARCH_RES_EVT 7   /* GATT discovery result event */
     56 #define BTA_GATTC_NOTIF_EVT 10       /* GATT attribute notification event */
     57 #define BTA_GATTC_EXEC_EVT 12        /* execute write complete event */
     58 #define BTA_GATTC_ACL_EVT 13         /* ACL up event */
     59 #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
     60 #define BTA_GATTC_SRVC_CHG_EVT 15    /* service change event */
     61 #define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
     62 #define BTA_GATTC_CFG_MTU_EVT 18     /* configure MTU complete event */
     63 #define BTA_GATTC_CONGEST_EVT 24     /* Congestion event */
     64 #define BTA_GATTC_PHY_UPDATE_EVT 25  /* PHY change event */
     65 #define BTA_GATTC_CONN_UPDATE_EVT 26 /* Connection parameters update event */
     66 
     67 typedef uint8_t tBTA_GATTC_EVT;
     68 
     69 typedef struct {
     70   uint16_t unit;  /* as UUIUD defined by SIG */
     71   uint16_t descr; /* as UUID as defined by SIG */
     72   tGATT_FORMAT format;
     73   int8_t exp;
     74   uint8_t name_spc; /* The name space of the description */
     75 } tBTA_GATT_CHAR_PRES;
     76 
     77 /* Characteristic Aggregate Format attribute value
     78  */
     79 #define BTA_GATT_AGGR_HANDLE_NUM_MAX 10
     80 typedef struct {
     81   uint8_t num_handle;
     82   uint16_t handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX];
     83 } tBTA_GATT_CHAR_AGGRE;
     84 
     85 typedef struct {
     86   uint16_t len;
     87   uint8_t* p_value;
     88 } tBTA_GATT_UNFMT;
     89 
     90 #define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel  */
     91 typedef uint16_t tBTA_GATT_REASON;
     92 
     93 #define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES
     94 
     95 typedef struct {
     96   uint8_t num_attr;
     97   uint16_t handles[BTA_GATTC_MULTI_MAX];
     98 } tBTA_GATTC_MULTI;
     99 
    100 enum {
    101   BTA_GATTC_ATTR_TYPE_INCL_SRVC,
    102   BTA_GATTC_ATTR_TYPE_CHAR,
    103   BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
    104   BTA_GATTC_ATTR_TYPE_SRVC
    105 };
    106 typedef uint8_t tBTA_GATTC_ATTR_TYPE;
    107 
    108 typedef struct {
    109   bluetooth::Uuid uuid;
    110   uint16_t s_handle;
    111   uint16_t e_handle; /* used for service only */
    112   uint8_t attr_type;
    113   uint8_t id;
    114   uint8_t prop;              /* used when attribute type is characteristic */
    115   bool is_primary;           /* used when attribute type is service */
    116   uint16_t incl_srvc_handle; /* used when attribute type is included service */
    117 } tBTA_GATTC_NV_ATTR;
    118 
    119 /* callback data structure */
    120 typedef struct {
    121   tGATT_STATUS status;
    122   tGATT_IF client_if;
    123 } tBTA_GATTC_REG;
    124 
    125 typedef struct {
    126   uint16_t conn_id;
    127   tGATT_STATUS status;
    128   uint16_t handle;
    129   uint16_t len;
    130   uint8_t value[GATT_MAX_ATTR_LEN];
    131 } tBTA_GATTC_READ;
    132 
    133 typedef struct {
    134   uint16_t conn_id;
    135   tGATT_STATUS status;
    136   uint16_t handle;
    137 } tBTA_GATTC_WRITE;
    138 
    139 typedef struct {
    140   uint16_t conn_id;
    141   tGATT_STATUS status;
    142 } tBTA_GATTC_EXEC_CMPL;
    143 
    144 typedef struct {
    145   uint16_t conn_id;
    146   tGATT_STATUS status;
    147 } tBTA_GATTC_SEARCH_CMPL;
    148 
    149 typedef struct {
    150   uint16_t conn_id;
    151   tBTA_GATT_ID service_uuid;
    152 } tBTA_GATTC_SRVC_RES;
    153 
    154 typedef struct {
    155   uint16_t conn_id;
    156   tGATT_STATUS status;
    157   uint16_t mtu;
    158 } tBTA_GATTC_CFG_MTU;
    159 
    160 typedef struct {
    161   tGATT_STATUS status;
    162   uint16_t conn_id;
    163   tGATT_IF client_if;
    164   RawAddress remote_bda;
    165   tBTA_TRANSPORT transport;
    166   uint16_t mtu;
    167 } tBTA_GATTC_OPEN;
    168 
    169 typedef struct {
    170   tGATT_STATUS status;
    171   uint16_t conn_id;
    172   tGATT_IF client_if;
    173   RawAddress remote_bda;
    174   tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect
    175                               event is reported */
    176 } tBTA_GATTC_CLOSE;
    177 
    178 typedef struct {
    179   uint16_t conn_id;
    180   RawAddress bda;
    181   uint16_t handle;
    182   uint16_t len;
    183   uint8_t value[GATT_MAX_ATTR_LEN];
    184   bool is_notify;
    185 } tBTA_GATTC_NOTIFY;
    186 
    187 typedef struct {
    188   uint16_t conn_id;
    189   bool congested; /* congestion indicator */
    190 } tBTA_GATTC_CONGEST;
    191 
    192 typedef struct {
    193   tGATT_STATUS status;
    194   tGATT_IF client_if;
    195   uint16_t conn_id;
    196   RawAddress remote_bda;
    197 } tBTA_GATTC_OPEN_CLOSE;
    198 
    199 typedef struct {
    200   tGATT_IF client_if;
    201   RawAddress remote_bda;
    202 } tBTA_GATTC_ENC_CMPL_CB;
    203 
    204 typedef struct {
    205   tGATT_IF server_if;
    206   uint16_t conn_id;
    207   uint8_t tx_phy;
    208   uint8_t rx_phy;
    209   tGATT_STATUS status;
    210 } tBTA_GATTC_PHY_UPDATE;
    211 
    212 typedef struct {
    213   tGATT_IF server_if;
    214   uint16_t conn_id;
    215   uint16_t interval;
    216   uint16_t latency;
    217   uint16_t timeout;
    218   tGATT_STATUS status;
    219 } tBTA_GATTC_CONN_UPDATE;
    220 
    221 typedef union {
    222   tGATT_STATUS status;
    223 
    224   tBTA_GATTC_SEARCH_CMPL search_cmpl; /* discovery complete */
    225   tBTA_GATTC_SRVC_RES srvc_res;       /* discovery result */
    226   tBTA_GATTC_REG reg_oper;            /* registration data */
    227   tBTA_GATTC_OPEN open;
    228   tBTA_GATTC_CLOSE close;
    229   tBTA_GATTC_READ read;           /* read attribute/descriptor data */
    230   tBTA_GATTC_WRITE write;         /* write complete data */
    231   tBTA_GATTC_EXEC_CMPL exec_cmpl; /*  execute complete */
    232   tBTA_GATTC_NOTIFY notify;       /* notification/indication event data */
    233   tBTA_GATTC_ENC_CMPL_CB enc_cmpl;
    234   RawAddress remote_bda;      /* service change event */
    235   tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */
    236   tBTA_GATTC_CONGEST congest;
    237   tBTA_GATTC_PHY_UPDATE phy_update;
    238   tBTA_GATTC_CONN_UPDATE conn_update;
    239 } tBTA_GATTC;
    240 
    241 /* GATTC enable callback function */
    242 typedef void(tBTA_GATTC_ENB_CBACK)(tGATT_STATUS status);
    243 
    244 /* Client callback function */
    245 typedef void(tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
    246 
    247 /* GATT Server Data Structure */
    248 /* Server callback function events */
    249 #define BTA_GATTS_REG_EVT 0
    250 #define BTA_GATTS_READ_CHARACTERISTIC_EVT \
    251   GATTS_REQ_TYPE_READ_CHARACTERISTIC                                 /* 1 */
    252 #define BTA_GATTS_READ_DESCRIPTOR_EVT GATTS_REQ_TYPE_READ_DESCRIPTOR /* 2 */
    253 #define BTA_GATTS_WRITE_CHARACTERISTIC_EVT \
    254   GATTS_REQ_TYPE_WRITE_CHARACTERISTIC                                  /* 3 */
    255 #define BTA_GATTS_WRITE_DESCRIPTOR_EVT GATTS_REQ_TYPE_WRITE_DESCRIPTOR /* 4 */
    256 #define BTA_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC             /* 5 */
    257 #define BTA_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU                           /* 6 */
    258 #define BTA_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF                         /* 7 */
    259 #define BTA_GATTS_DEREG_EVT 8
    260 #define BTA_GATTS_DELELTE_EVT 11
    261 #define BTA_GATTS_STOP_EVT 13
    262 #define BTA_GATTS_CONNECT_EVT 14
    263 #define BTA_GATTS_DISCONNECT_EVT 15
    264 #define BTA_GATTS_OPEN_EVT 16
    265 #define BTA_GATTS_CANCEL_OPEN_EVT 17
    266 #define BTA_GATTS_CLOSE_EVT 18
    267 #define BTA_GATTS_CONGEST_EVT 20
    268 #define BTA_GATTS_PHY_UPDATE_EVT 21
    269 #define BTA_GATTS_CONN_UPDATE_EVT 22
    270 
    271 typedef uint8_t tBTA_GATTS_EVT;
    272 
    273 #define BTA_GATTS_INVALID_APP 0xff
    274 
    275 #define BTA_GATTS_INVALID_IF 0
    276 
    277 #ifndef BTA_GATTC_CHAR_DESCR_MAX
    278 #define BTA_GATTC_CHAR_DESCR_MAX 7
    279 #endif
    280 
    281 /***********************  NV callback Data Definitions   **********************
    282  */
    283 typedef struct {
    284   bluetooth::Uuid app_uuid128;
    285   bluetooth::Uuid svc_uuid;
    286   uint16_t svc_inst;
    287   uint16_t s_handle;
    288   uint16_t e_handle;
    289   bool is_primary; /* primary service or secondary */
    290 } tBTA_GATTS_HNDL_RANGE;
    291 
    292 typedef struct {
    293   tGATT_STATUS status;
    294   RawAddress remote_bda;
    295   uint32_t trans_id;
    296   uint16_t conn_id;
    297   tGATTS_DATA* p_data;
    298 } tBTA_GATTS_REQ;
    299 
    300 typedef struct {
    301   tGATT_IF server_if;
    302   tGATT_STATUS status;
    303   bluetooth::Uuid uuid;
    304 } tBTA_GATTS_REG_OPER;
    305 
    306 typedef struct {
    307   tGATT_IF server_if;
    308   uint16_t service_id;
    309   uint16_t svc_instance;
    310   bool is_primary;
    311   tGATT_STATUS status;
    312   bluetooth::Uuid uuid;
    313 } tBTA_GATTS_CREATE;
    314 
    315 typedef struct {
    316   tGATT_IF server_if;
    317   uint16_t service_id;
    318   tGATT_STATUS status;
    319 } tBTA_GATTS_SRVC_OPER;
    320 
    321 typedef struct {
    322   tGATT_IF server_if;
    323   RawAddress remote_bda;
    324   uint16_t conn_id;
    325   tBTA_GATT_REASON reason; /* report disconnect reason */
    326   tGATT_TRANSPORT transport;
    327 } tBTA_GATTS_CONN;
    328 
    329 typedef struct {
    330   uint16_t conn_id;
    331   bool congested; /* report channel congestion indicator */
    332 } tBTA_GATTS_CONGEST;
    333 
    334 typedef struct {
    335   uint16_t conn_id;        /* connection ID */
    336   tGATT_STATUS status;     /* notification/indication status */
    337 } tBTA_GATTS_CONF;
    338 
    339 typedef struct {
    340   tGATT_IF server_if;
    341   uint16_t conn_id;
    342   uint8_t tx_phy;
    343   uint8_t rx_phy;
    344   tGATT_STATUS status;
    345 } tBTA_GATTS_PHY_UPDATE;
    346 
    347 typedef struct {
    348   tGATT_IF server_if;
    349   uint16_t conn_id;
    350   uint16_t interval;
    351   uint16_t latency;
    352   uint16_t timeout;
    353   tGATT_STATUS status;
    354 } tBTA_GATTS_CONN_UPDATE;
    355 
    356 /* GATTS callback data */
    357 typedef union {
    358   tBTA_GATTS_REG_OPER reg_oper;
    359   tBTA_GATTS_CREATE create;
    360   tBTA_GATTS_SRVC_OPER srvc_oper;
    361   tGATT_STATUS status; /* BTA_GATTS_LISTEN_EVT */
    362   tBTA_GATTS_REQ req_data;
    363   tBTA_GATTS_CONN conn;             /* BTA_GATTS_CONN_EVT */
    364   tBTA_GATTS_CONGEST congest;       /* BTA_GATTS_CONGEST_EVT callback data */
    365   tBTA_GATTS_CONF confirm;          /* BTA_GATTS_CONF_EVT callback data */
    366   tBTA_GATTS_PHY_UPDATE phy_update; /* BTA_GATTS_PHY_UPDATE_EVT callback data */
    367   tBTA_GATTS_CONN_UPDATE
    368       conn_update; /* BTA_GATTS_CONN_UPDATE_EVT callback data */
    369 } tBTA_GATTS;
    370 
    371 /* GATTS enable callback function */
    372 typedef void(tBTA_GATTS_ENB_CBACK)(tGATT_STATUS status);
    373 
    374 /* Server callback function */
    375 typedef void(tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS* p_data);
    376 
    377 struct tBTA_GATTC_CHARACTERISTIC;
    378 struct tBTA_GATTC_DESCRIPTOR;
    379 struct tBTA_GATTC_INCLUDED_SVC;
    380 
    381 struct tBTA_GATTC_SERVICE {
    382   bluetooth::Uuid uuid;
    383   bool is_primary;
    384   uint16_t handle;
    385   uint16_t s_handle;
    386   uint16_t e_handle;
    387   std::vector<tBTA_GATTC_CHARACTERISTIC> characteristics;
    388   std::vector<tBTA_GATTC_INCLUDED_SVC> included_svc;
    389 };
    390 
    391 struct tBTA_GATTC_CHARACTERISTIC {
    392   bluetooth::Uuid uuid;
    393   // this is used only during discovery, and not persisted in cache
    394   uint16_t declaration_handle;
    395   uint16_t value_handle;
    396   tGATT_CHAR_PROP properties;
    397   std::vector<tBTA_GATTC_DESCRIPTOR> descriptors;
    398 };
    399 
    400 struct tBTA_GATTC_DESCRIPTOR {
    401   bluetooth::Uuid uuid;
    402   uint16_t handle;
    403 };
    404 
    405 struct tBTA_GATTC_INCLUDED_SVC {
    406   bluetooth::Uuid uuid;
    407   uint16_t handle;
    408   tBTA_GATTC_SERVICE* owning_service; /* owning service*/
    409   tBTA_GATTC_SERVICE* included_service;
    410 };
    411 
    412 /*****************************************************************************
    413  *  External Function Declarations
    414  ****************************************************************************/
    415 
    416 /**************************
    417  *  Client Functions
    418  **************************/
    419 
    420 /*******************************************************************************
    421  *
    422  * Function         BTA_GATTC_Disable
    423  *
    424  * Description      This function is called to disable the GATTC module
    425  *
    426  * Parameters       None.
    427  *
    428  * Returns          None
    429  *
    430  ******************************************************************************/
    431 extern void BTA_GATTC_Disable(void);
    432 
    433 using BtaAppRegisterCallback =
    434     base::Callback<void(uint8_t /* app_id */, uint8_t /* status */)>;
    435 
    436 /**
    437  * This function is called to register application callbacks with BTA GATTC
    438  *module.
    439  * p_client_cb - pointer to the application callback function.
    440  **/
    441 extern void BTA_GATTC_AppRegister(tBTA_GATTC_CBACK* p_client_cb,
    442                                   BtaAppRegisterCallback cb);
    443 
    444 /*******************************************************************************
    445  *
    446  * Function         BTA_GATTC_AppDeregister
    447  *
    448  * Description      This function is called to deregister an application
    449  *                  from BTA GATTC module.
    450  *
    451  * Parameters       client_if - client interface identifier.
    452  *
    453  * Returns          None
    454  *
    455  ******************************************************************************/
    456 extern void BTA_GATTC_AppDeregister(tGATT_IF client_if);
    457 
    458 /*******************************************************************************
    459  *
    460  * Function         BTA_GATTC_Open
    461  *
    462  * Description      Open a direct connection or add a background auto connection
    463  *                  bd address
    464  *
    465  * Parameters       client_if: server interface.
    466  *                  remote_bda: remote device BD address.
    467  *                  is_direct: direct connection or background auto connection
    468  *                  initiating_phys: LE PHY to use, optional
    469  *
    470  ******************************************************************************/
    471 extern void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
    472                            bool is_direct, tGATT_TRANSPORT transport,
    473                            bool opportunistic);
    474 extern void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
    475                            bool is_direct, tGATT_TRANSPORT transport,
    476                            bool opportunistic, uint8_t initiating_phys);
    477 
    478 /*******************************************************************************
    479  *
    480  * Function         BTA_GATTC_CancelOpen
    481  *
    482  * Description      Open a direct connection or add a background auto connection
    483  *                  bd address
    484  *
    485  * Parameters       client_if: server interface.
    486  *                  remote_bda: remote device BD address.
    487  *                  is_direct: direct connection or background auto connection
    488  *
    489  * Returns          void
    490  *
    491  ******************************************************************************/
    492 extern void BTA_GATTC_CancelOpen(tGATT_IF client_if,
    493                                  const RawAddress& remote_bda, bool is_direct);
    494 
    495 /*******************************************************************************
    496  *
    497  * Function         BTA_GATTC_Close
    498  *
    499  * Description      Close a connection to a GATT server.
    500  *
    501  * Parameters       conn_id: connectino ID to be closed.
    502  *
    503  * Returns          void
    504  *
    505  ******************************************************************************/
    506 extern void BTA_GATTC_Close(uint16_t conn_id);
    507 
    508 /*******************************************************************************
    509  *
    510  * Function         BTA_GATTC_ServiceSearchRequest
    511  *
    512  * Description      This function is called to request a GATT service discovery
    513  *                  on a GATT server. This function report service search result
    514  *                  by a callback event, and followed by a service search
    515  *                  complete event.
    516  *
    517  * Parameters       conn_id: connection ID.
    518  *                  p_srvc_uuid: a UUID of the service application is interested
    519  *                               in. If Null, discover for all services.
    520  *
    521  * Returns          None
    522  *
    523  ******************************************************************************/
    524 extern void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,
    525                                            bluetooth::Uuid* p_srvc_uuid);
    526 
    527 /**
    528  * This function is called to send "Find service by UUID" request. Used only for
    529  * PTS tests.
    530  */
    531 extern void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id,
    532                                             const bluetooth::Uuid& p_srvc_uuid);
    533 
    534 /*******************************************************************************
    535  *
    536  * Function         BTA_GATTC_GetServices
    537  *
    538  * Description      This function is called to find the services on the given
    539  *                  server.
    540  *
    541  * Parameters       conn_id: connection ID which identify the server.
    542  *
    543  * Returns          returns list of tBTA_GATTC_SERVICE or NULL.
    544  *
    545  ******************************************************************************/
    546 extern const std::vector<tBTA_GATTC_SERVICE>* BTA_GATTC_GetServices(
    547     uint16_t conn_id);
    548 
    549 /*******************************************************************************
    550  *
    551  * Function         BTA_GATTC_GetCharacteristic
    552  *
    553  * Description      This function is called to find the characteristic on the
    554  *                  given server.
    555  *
    556  * Parameters       conn_id: connection ID which identify the server.
    557  *                  handle: characteristic handle
    558  *
    559  * Returns          returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
    560  *
    561  ******************************************************************************/
    562 extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(
    563     uint16_t conn_id, uint16_t handle);
    564 
    565 /*******************************************************************************
    566  *
    567  * Function         BTA_GATTC_GetDescriptor
    568  *
    569  * Description      This function is called to find the characteristic on the
    570  *                  given server.
    571  *
    572  * Parameters       conn_id: connection ID which identify the server.
    573  *                  handle: descriptor handle
    574  *
    575  * Returns          returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
    576  *
    577  ******************************************************************************/
    578 extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(uint16_t conn_id,
    579                                                             uint16_t handle);
    580 
    581 /* Return characteristic that owns descriptor with handle equal to |handle|, or
    582  * NULL */
    583 extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetOwningCharacteristic(
    584     uint16_t conn_id, uint16_t handle);
    585 
    586 /* Return service that owns descriptor or characteristic with handle equal to
    587  * |handle|, or NULL */
    588 extern const tBTA_GATTC_SERVICE* BTA_GATTC_GetOwningService(uint16_t conn_id,
    589                                                             uint16_t handle);
    590 
    591 /*******************************************************************************
    592  *
    593  * Function         BTA_GATTC_GetGattDb
    594  *
    595  * Description      This function is called to get gatt db.
    596  *
    597  * Parameters       conn_id: connection ID which identify the server.
    598  *                  db: output parameter which will contain gatt db copy.
    599  *                      Caller is responsible for freeing it.
    600  *                  count: number of elements in db.
    601  *
    602  ******************************************************************************/
    603 extern void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle,
    604                                 uint16_t end_handle, btgatt_db_element_t** db,
    605                                 int* count);
    606 
    607 typedef void (*GATT_READ_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
    608                                 uint16_t handle, uint16_t len, uint8_t* value,
    609                                 void* data);
    610 typedef void (*GATT_WRITE_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
    611                                  uint16_t handle, void* data);
    612 
    613 /*******************************************************************************
    614  *
    615  * Function         BTA_GATTC_ReadCharacteristic
    616  *
    617  * Description      This function is called to read a characteristics value
    618  *
    619  * Parameters       conn_id - connectino ID.
    620  *                  handle - characteritic handle to read.
    621  *
    622  * Returns          None
    623  *
    624  ******************************************************************************/
    625 void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle,
    626                                   tGATT_AUTH_REQ auth_req,
    627                                   GATT_READ_OP_CB callback, void* cb_data);
    628 
    629 /**
    630  * This function is called to read a value of characteristic with uuid equal to
    631  * |uuid|
    632  */
    633 void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, const bluetooth::Uuid& uuid,
    634                                  uint16_t s_handle, uint16_t e_handle,
    635                                  tGATT_AUTH_REQ auth_req,
    636                                  GATT_READ_OP_CB callback, void* cb_data);
    637 
    638 /*******************************************************************************
    639  *
    640  * Function         BTA_GATTC_ReadCharDescr
    641  *
    642  * Description      This function is called to read a descriptor value.
    643  *
    644  * Parameters       conn_id - connection ID.
    645  *                  handle - descriptor handle to read.
    646  *
    647  * Returns          None
    648  *
    649  ******************************************************************************/
    650 void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle,
    651                              tGATT_AUTH_REQ auth_req, GATT_READ_OP_CB callback,
    652                              void* cb_data);
    653 
    654 /*******************************************************************************
    655  *
    656  * Function         BTA_GATTC_WriteCharValue
    657  *
    658  * Description      This function is called to write characteristic value.
    659  *
    660  * Parameters       conn_id - connection ID.
    661  *                  handle - characteristic handle to write.
    662  *                  write_type - type of write.
    663  *                  value - the value to be written.
    664  *
    665  * Returns          None
    666  *
    667  ******************************************************************************/
    668 void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle,
    669                               tGATT_WRITE_TYPE write_type,
    670                               std::vector<uint8_t> value,
    671                               tGATT_AUTH_REQ auth_req,
    672                               GATT_WRITE_OP_CB callback, void* cb_data);
    673 
    674 /*******************************************************************************
    675  *
    676  * Function         BTA_GATTC_WriteCharDescr
    677  *
    678  * Description      This function is called to write descriptor value.
    679  *
    680  * Parameters       conn_id - connection ID
    681  *                  handle - descriptor handle to write.
    682  *                  value - the value to be written.
    683  *
    684  * Returns          None
    685  *
    686  ******************************************************************************/
    687 void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle,
    688                               std::vector<uint8_t> value,
    689                               tGATT_AUTH_REQ auth_req,
    690                               GATT_WRITE_OP_CB callback, void* cb_data);
    691 
    692 /*******************************************************************************
    693  *
    694  * Function         BTA_GATTC_SendIndConfirm
    695  *
    696  * Description      This function is called to send handle value confirmation.
    697  *
    698  * Parameters       conn_id - connection ID.
    699  *                  handle - characteristic handle to confirm.
    700  *
    701  * Returns          None
    702  *
    703  ******************************************************************************/
    704 extern void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t handle);
    705 
    706 /*******************************************************************************
    707  *
    708  * Function         BTA_GATTC_RegisterForNotifications
    709  *
    710  * Description      This function is called to register for notification of a
    711  *                  service.
    712  *
    713  * Parameters       client_if - client interface.
    714  *                  remote_bda - target GATT server.
    715  *                  handle - GATT characteristic handle.
    716  *
    717  * Returns          OK if registration succeed, otherwise failed.
    718  *
    719  ******************************************************************************/
    720 extern tGATT_STATUS BTA_GATTC_RegisterForNotifications(
    721     tGATT_IF client_if, const RawAddress& remote_bda, uint16_t handle);
    722 
    723 /*******************************************************************************
    724  *
    725  * Function         BTA_GATTC_DeregisterForNotifications
    726  *
    727  * Description      This function is called to de-register for notification of a
    728  *                  service.
    729  *
    730  * Parameters       client_if - client interface.
    731  *                  remote_bda - target GATT server.
    732  *                  handle - GATT characteristic handle.
    733  *
    734  * Returns          OK if deregistration succeed, otherwise failed.
    735  *
    736  ******************************************************************************/
    737 extern tGATT_STATUS BTA_GATTC_DeregisterForNotifications(
    738     tGATT_IF client_if, const RawAddress& remote_bda, uint16_t handle);
    739 
    740 /*******************************************************************************
    741  *
    742  * Function         BTA_GATTC_PrepareWrite
    743  *
    744  * Description      This function is called to prepare write a characteristic
    745  *                  value.
    746  *
    747  * Parameters       conn_id - connection ID.
    748  *                  handle - GATT characteritic handle.
    749  *                  offset - offset of the write value.
    750  *                  value - the value to be written.
    751  *
    752  * Returns          None
    753  *
    754  ******************************************************************************/
    755 extern void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle,
    756                                    uint16_t offset, std::vector<uint8_t> value,
    757                                    tGATT_AUTH_REQ auth_req,
    758                                    GATT_WRITE_OP_CB callback, void* cb_data);
    759 
    760 /*******************************************************************************
    761  *
    762  * Function         BTA_GATTC_ExecuteWrite
    763  *
    764  * Description      This function is called to execute write a prepare write
    765  *                  sequence.
    766  *
    767  * Parameters       conn_id - connection ID.
    768  *                    is_execute - execute or cancel.
    769  *
    770  * Returns          None
    771  *
    772  ******************************************************************************/
    773 extern void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute);
    774 
    775 /*******************************************************************************
    776  *
    777  * Function         BTA_GATTC_ReadMultiple
    778  *
    779  * Description      This function is called to read multiple characteristic or
    780  *                  characteristic descriptors.
    781  *
    782  * Parameters       conn_id - connectino ID.
    783  *                    p_read_multi - read multiple parameters.
    784  *
    785  * Returns          None
    786  *
    787  ******************************************************************************/
    788 extern void BTA_GATTC_ReadMultiple(uint16_t conn_id,
    789                                    tBTA_GATTC_MULTI* p_read_multi,
    790                                    tGATT_AUTH_REQ auth_req);
    791 
    792 /*******************************************************************************
    793  *
    794  * Function         BTA_GATTC_Refresh
    795  *
    796  * Description      Refresh the server cache of the remote device
    797  *
    798  * Parameters       remote_bda: remote device BD address.
    799  *
    800  * Returns          void
    801  *
    802  ******************************************************************************/
    803 extern void BTA_GATTC_Refresh(const RawAddress& remote_bda);
    804 
    805 /*******************************************************************************
    806  *
    807  * Function         BTA_GATTC_ConfigureMTU
    808  *
    809  * Description      Configure the MTU size in the GATT channel. This can be done
    810  *                  only once per connection.
    811  *
    812  * Parameters       conn_id: connection ID.
    813  *                  mtu: desired MTU size to use.
    814  *
    815  * Returns          void
    816  *
    817  ******************************************************************************/
    818 extern void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
    819 
    820 /*******************************************************************************
    821  *  BTA GATT Server API
    822  ******************************************************************************/
    823 
    824 /*******************************************************************************
    825  *
    826  * Function         BTA_GATTS_Init
    827  *
    828  * Description      This function is called to initalize GATTS module
    829  *
    830  * Parameters       None
    831  *
    832  * Returns          None
    833  *
    834  ******************************************************************************/
    835 extern void BTA_GATTS_Init();
    836 
    837 /*******************************************************************************
    838  *
    839  * Function         BTA_GATTS_Disable
    840  *
    841  * Description      This function is called to disable GATTS module
    842  *
    843  * Parameters       None.
    844  *
    845  * Returns          None
    846  *
    847  ******************************************************************************/
    848 extern void BTA_GATTS_Disable(void);
    849 
    850 /*******************************************************************************
    851  *
    852  * Function         BTA_GATTS_AppRegister
    853  *
    854  * Description      This function is called to register application callbacks
    855  *                    with BTA GATTS module.
    856  *
    857  * Parameters       p_app_uuid - applicaiton UUID
    858  *                  p_cback - pointer to the application callback function.
    859  *
    860  * Returns          None
    861  *
    862  ******************************************************************************/
    863 extern void BTA_GATTS_AppRegister(const bluetooth::Uuid& app_uuid,
    864                                   tBTA_GATTS_CBACK* p_cback);
    865 
    866 /*******************************************************************************
    867  *
    868  * Function         BTA_GATTS_AppDeregister
    869  *
    870  * Description      De-register with BTA GATT Server.
    871  *
    872  * Parameters       server_if: server interface
    873  *
    874  * Returns          void
    875  *
    876  ******************************************************************************/
    877 extern void BTA_GATTS_AppDeregister(tGATT_IF server_if);
    878 
    879 /*******************************************************************************
    880  *
    881  * Function         BTA_GATTS_AddService
    882  *
    883  * Description      Add the given |service| and all included elements to the
    884  *                  GATT database. a |BTA_GATTS_ADD_SRVC_EVT| is triggered to
    885  *                  report the status and attribute handles.
    886  *
    887  * Parameters       server_if: server interface.
    888  *                  service: pointer to vector describing service.
    889  *
    890  * Returns          Returns |GATT_SUCCESS| on success or |GATT_ERROR| if the
    891  *                  service cannot be added.
    892  *
    893  ******************************************************************************/
    894 typedef base::Callback<void(uint8_t status, int server_if,
    895                             std::vector<btgatt_db_element_t> service)>
    896     BTA_GATTS_AddServiceCb;
    897 
    898 extern void BTA_GATTS_AddService(tGATT_IF server_if,
    899                                  std::vector<btgatt_db_element_t> service,
    900                                  BTA_GATTS_AddServiceCb cb);
    901 
    902 /*******************************************************************************
    903  *
    904  * Function         BTA_GATTS_DeleteService
    905  *
    906  * Description      This function is called to delete a service. When this is
    907  *                  done, a callback event BTA_GATTS_DELETE_EVT is report with
    908  *                  the status.
    909  *
    910  * Parameters       service_id: service_id to be deleted.
    911  *
    912  * Returns          returns none.
    913  *
    914  ******************************************************************************/
    915 extern void BTA_GATTS_DeleteService(uint16_t service_id);
    916 
    917 /*******************************************************************************
    918  *
    919  * Function         BTA_GATTS_StopService
    920  *
    921  * Description      This function is called to stop a service.
    922  *
    923  * Parameters       service_id - service to be topped.
    924  *
    925  * Returns          None
    926  *
    927  ******************************************************************************/
    928 extern void BTA_GATTS_StopService(uint16_t service_id);
    929 
    930 /*******************************************************************************
    931  *
    932  * Function         BTA_GATTS_HandleValueIndication
    933  *
    934  * Description      This function is called to read a characteristics
    935  *                  descriptor.
    936  *
    937  * Parameters       conn_id - connection identifier.
    938  *                  attr_id - attribute ID to indicate.
    939  *                  value - data to indicate.
    940  *                  need_confirm - if this indication expects a confirmation or
    941  *                                 not.
    942  *
    943  * Returns          None
    944  *
    945  ******************************************************************************/
    946 extern void BTA_GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_id,
    947                                             std::vector<uint8_t> value,
    948                                             bool need_confirm);
    949 
    950 /*******************************************************************************
    951  *
    952  * Function         BTA_GATTS_SendRsp
    953  *
    954  * Description      This function is called to send a response to a request.
    955  *
    956  * Parameters       conn_id - connection identifier.
    957  *                  trans_id - transaction ID.
    958  *                  status - response status
    959  *                  p_msg - response data.
    960  *
    961  * Returns          None
    962  *
    963  ******************************************************************************/
    964 extern void BTA_GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id,
    965                               tGATT_STATUS status, tGATTS_RSP* p_msg);
    966 
    967 /*******************************************************************************
    968  *
    969  * Function         BTA_GATTS_Open
    970  *
    971  * Description      Open a direct open connection or add a background auto
    972  *                  connection bd address
    973  *
    974  * Parameters       server_if: server interface.
    975  *                  remote_bda: remote device BD address.
    976  *                  is_direct: direct connection or background auto connection
    977  *
    978  * Returns          void
    979  *
    980  ******************************************************************************/
    981 extern void BTA_GATTS_Open(tGATT_IF server_if, const RawAddress& remote_bda,
    982                            bool is_direct, tGATT_TRANSPORT transport);
    983 
    984 /*******************************************************************************
    985  *
    986  * Function         BTA_GATTS_CancelOpen
    987  *
    988  * Description      Cancel a direct open connection or remove a background auto
    989  *                  connection bd address
    990  *
    991  * Parameters       server_if: server interface.
    992  *                  remote_bda: remote device BD address.
    993  *                  is_direct: direct connection or background auto connection
    994  *
    995  * Returns          void
    996  *
    997  ******************************************************************************/
    998 extern void BTA_GATTS_CancelOpen(tGATT_IF server_if,
    999                                  const RawAddress& remote_bda, bool is_direct);
   1000 
   1001 /*******************************************************************************
   1002  *
   1003  * Function         BTA_GATTS_Close
   1004  *
   1005  * Description      Close a connection  a remote device.
   1006  *
   1007  * Parameters       conn_id: connectino ID to be closed.
   1008  *
   1009  * Returns          void
   1010  *
   1011  ******************************************************************************/
   1012 extern void BTA_GATTS_Close(uint16_t conn_id);
   1013 
   1014 #endif /* BTA_GATT_API_H */
   1015