OSDN Git Service

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