gatt_api.h 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 1999-2012 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. #ifndef GATT_API_H
  19. #define GATT_API_H
  20. #include "common/bt_target.h"
  21. #include "stack/gattdefs.h"
  22. #include "stack/btm_ble_api.h"
  23. /*****************************************************************************
  24. ** Constants
  25. *****************************************************************************/
  26. /* Success code and error codes */
  27. #define GATT_SUCCESS 0x00
  28. #define GATT_INVALID_HANDLE 0x01
  29. #define GATT_READ_NOT_PERMIT 0x02
  30. #define GATT_WRITE_NOT_PERMIT 0x03
  31. #define GATT_INVALID_PDU 0x04
  32. #define GATT_INSUF_AUTHENTICATION 0x05
  33. #define GATT_REQ_NOT_SUPPORTED 0x06
  34. #define GATT_INVALID_OFFSET 0x07
  35. #define GATT_INSUF_AUTHORIZATION 0x08
  36. #define GATT_PREPARE_Q_FULL 0x09
  37. #define GATT_NOT_FOUND 0x0a
  38. #define GATT_NOT_LONG 0x0b
  39. #define GATT_INSUF_KEY_SIZE 0x0c
  40. #define GATT_INVALID_ATTR_LEN 0x0d
  41. #define GATT_ERR_UNLIKELY 0x0e
  42. #define GATT_INSUF_ENCRYPTION 0x0f
  43. #define GATT_UNSUPPORT_GRP_TYPE 0x10
  44. #define GATT_INSUF_RESOURCE 0x11
  45. #define GATT_NO_RESOURCES 0x80
  46. #define GATT_INTERNAL_ERROR 0x81
  47. #define GATT_WRONG_STATE 0x82
  48. #define GATT_DB_FULL 0x83
  49. #define GATT_BUSY 0x84
  50. #define GATT_ERROR 0x85
  51. #define GATT_CMD_STARTED 0x86
  52. #define GATT_ILLEGAL_PARAMETER 0x87
  53. #define GATT_PENDING 0x88
  54. #define GATT_AUTH_FAIL 0x89
  55. #define GATT_MORE 0x8a
  56. #define GATT_INVALID_CFG 0x8b
  57. #define GATT_SERVICE_STARTED 0x8c
  58. #define GATT_ENCRYPED_MITM GATT_SUCCESS
  59. #define GATT_ENCRYPED_NO_MITM 0x8d
  60. #define GATT_NOT_ENCRYPTED 0x8e
  61. #define GATT_CONGESTED 0x8f
  62. #define GATT_DUP_REG 0x90
  63. #define GATT_ALREADY_OPEN 0x91
  64. #define GATT_CANCEL 0x92
  65. /* 0xE0 ~ 0xFC reserved for future use */
  66. #define GATT_STACK_RSP 0xE0
  67. #define GATT_APP_RSP 0xE1
  68. //Error caused by customer application or stack bug
  69. #define GATT_UNKNOWN_ERROR 0XEF
  70. #define GATT_CCC_CFG_ERR 0xFD /* Client Characteristic Configuration Descriptor Improperly Configured */
  71. #define GATT_PRC_IN_PROGRESS 0xFE /* Procedure Already in progress */
  72. #define GATT_OUT_OF_RANGE 0xFF /* Attribute value out of range */
  73. typedef UINT8 tGATT_STATUS;
  74. #define GATT_RSP_ERROR 0x01
  75. #define GATT_REQ_MTU 0x02
  76. #define GATT_RSP_MTU 0x03
  77. #define GATT_REQ_FIND_INFO 0x04
  78. #define GATT_RSP_FIND_INFO 0x05
  79. #define GATT_REQ_FIND_TYPE_VALUE 0x06
  80. #define GATT_RSP_FIND_TYPE_VALUE 0x07
  81. #define GATT_REQ_READ_BY_TYPE 0x08
  82. #define GATT_RSP_READ_BY_TYPE 0x09
  83. #define GATT_REQ_READ 0x0A
  84. #define GATT_RSP_READ 0x0B
  85. #define GATT_REQ_READ_BLOB 0x0C
  86. #define GATT_RSP_READ_BLOB 0x0D
  87. #define GATT_REQ_READ_MULTI 0x0E
  88. #define GATT_RSP_READ_MULTI 0x0F
  89. #define GATT_REQ_READ_BY_GRP_TYPE 0x10
  90. #define GATT_RSP_READ_BY_GRP_TYPE 0x11
  91. #define GATT_REQ_WRITE 0x12 /* 0001-0010 (write)*/
  92. #define GATT_RSP_WRITE 0x13
  93. #define GATT_CMD_WRITE 0x52 /* changed in V4.0 01001-0010(write cmd)*/
  94. #define GATT_REQ_PREPARE_WRITE 0x16
  95. #define GATT_RSP_PREPARE_WRITE 0x17
  96. #define GATT_REQ_EXEC_WRITE 0x18
  97. #define GATT_RSP_EXEC_WRITE 0x19
  98. #define GATT_HANDLE_VALUE_NOTIF 0x1B
  99. #define GATT_HANDLE_VALUE_IND 0x1D
  100. #define GATT_HANDLE_VALUE_CONF 0x1E
  101. #define GATT_SIGN_CMD_WRITE 0xD2 /* changed in V4.0 1101-0010 (signed write) see write cmd above*/
  102. #define GATT_OP_CODE_MAX GATT_HANDLE_VALUE_CONF + 1 /* 0x1E = 30 + 1 = 31*/
  103. #define GATT_COMMAND_FLAG 0x40 /* Command Flag: set to one means command */
  104. #define GATT_HANDLE_IS_VALID(x) ((x) != 0)
  105. #define GATT_CONN_UNKNOWN 0
  106. #define GATT_CONN_L2C_FAILURE 1 /* general L2cap failure */
  107. #define GATT_CONN_TIMEOUT HCI_ERR_CONNECTION_TOUT /* 0x08 connection timeout */
  108. #define GATT_CONN_TERMINATE_PEER_USER HCI_ERR_PEER_USER /* 0x13 connection terminate by peer user */
  109. #define GATT_CONN_TERMINATE_LOCAL_HOST HCI_ERR_CONN_CAUSE_LOCAL_HOST /* 0x16 connectionterminated by local host */
  110. #define GATT_CONN_FAIL_ESTABLISH HCI_ERR_CONN_FAILED_ESTABLISHMENT/* 0x03E connection fail to establish */
  111. #define GATT_CONN_LMP_TIMEOUT HCI_ERR_LMP_RESPONSE_TIMEOUT /* 0x22 connection fail for LMP response tout */
  112. #define GATT_CONN_CANCEL L2CAP_CONN_CANCEL /* 0x0100 L2CAP connection cancelled */
  113. typedef UINT16 tGATT_DISCONN_REASON;
  114. /* MAX GATT MTU size
  115. */
  116. #ifndef GATT_MAX_MTU_SIZE
  117. #define GATT_MAX_MTU_SIZE 517
  118. #endif
  119. /* max length of an attribute value
  120. */
  121. #ifndef GATT_MAX_ATTR_LEN
  122. #define GATT_MAX_ATTR_LEN 600
  123. #endif
  124. /* default GATT MTU size over LE link
  125. */
  126. #define GATT_DEF_BLE_MTU_SIZE 23
  127. /* invalid connection ID
  128. */
  129. #define GATT_INVALID_CONN_ID 0xFFFF
  130. #ifndef GATT_CL_MAX_LCB
  131. #define GATT_CL_MAX_LCB 12 // 22
  132. #endif
  133. #ifndef GATT_MAX_SCCB
  134. #define GATT_MAX_SCCB 10
  135. #endif
  136. /* GATT notification caching timer, default to be three seconds
  137. */
  138. #ifndef GATTC_NOTIF_TIMEOUT
  139. #define GATTC_NOTIF_TIMEOUT 3
  140. #endif
  141. /*****************************************************************************
  142. ** GATT Structure Definition
  143. *****************************************************************************/
  144. /* Attribute permissions
  145. */
  146. #define GATT_PERM_READ (1 << 0) /* bit 0 */
  147. #define GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 */
  148. #define GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 */
  149. #define GATT_PERM_WRITE (1 << 4) /* bit 4 */
  150. #define GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 */
  151. #define GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 */
  152. #define GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 */
  153. #define GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 */
  154. #define GATT_PERM_READ_AUTHORIZATION (1 << 9) /* bit 9 */
  155. #define GATT_PERM_WRITE_AUTHORIZATION (1 << 10)/* bit 10 */
  156. typedef UINT16 tGATT_PERM;
  157. #define GATT_ENCRYPT_KEY_SIZE_MASK (0xF000) /* the MS nibble of tGATT_PERM; key size 7=0; size 16=9 */
  158. #define GATT_READ_ALLOWED (GATT_PERM_READ | GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM | GATT_PERM_READ_AUTHORIZATION)
  159. #define GATT_READ_AUTH_REQUIRED (GATT_PERM_READ_ENCRYPTED)
  160. #define GATT_READ_MITM_REQUIRED (GATT_PERM_READ_ENC_MITM)
  161. #define GATT_READ_ENCRYPTED_REQUIRED (GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM)
  162. #define GATT_READ_AUTHORIZATION (GATT_PERM_READ_AUTHORIZATION)
  163. #define GATT_WRITE_ALLOWED (GATT_PERM_WRITE | GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM | \
  164. GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM | GATT_PERM_WRITE_AUTHORIZATION)
  165. #define GATT_WRITE_AUTH_REQUIRED (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_SIGNED)
  166. #define GATT_WRITE_MITM_REQUIRED (GATT_PERM_WRITE_ENC_MITM | GATT_PERM_WRITE_SIGNED_MITM)
  167. #define GATT_WRITE_ENCRYPTED_PERM (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM)
  168. #define GATT_WRITE_SIGNED_PERM (GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM)
  169. #define GATT_WRITE_AUTHORIZATION (GATT_PERM_WRITE_AUTHORIZATION)
  170. /* Characteristic properties
  171. */
  172. #define GATT_CHAR_PROP_BIT_BROADCAST (1 << 0)
  173. #define GATT_CHAR_PROP_BIT_READ (1 << 1)
  174. #define GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2)
  175. #define GATT_CHAR_PROP_BIT_WRITE (1 << 3)
  176. #define GATT_CHAR_PROP_BIT_NOTIFY (1 << 4)
  177. #define GATT_CHAR_PROP_BIT_INDICATE (1 << 5)
  178. #define GATT_CHAR_PROP_BIT_AUTH (1 << 6)
  179. #define GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7)
  180. typedef UINT8 tGATT_CHAR_PROP;
  181. /* Format of the value of a characteristic. enumeration type
  182. */
  183. enum {
  184. GATT_FORMAT_RES, /* rfu */
  185. GATT_FORMAT_BOOL, /* 0x01 boolean */
  186. GATT_FORMAT_2BITS, /* 0x02 2 bit */
  187. GATT_FORMAT_NIBBLE, /* 0x03 nibble */
  188. GATT_FORMAT_UINT8, /* 0x04 uint8 */
  189. GATT_FORMAT_UINT12, /* 0x05 uint12 */
  190. GATT_FORMAT_UINT16, /* 0x06 uint16 */
  191. GATT_FORMAT_UINT24, /* 0x07 uint24 */
  192. GATT_FORMAT_UINT32, /* 0x08 uint32 */
  193. GATT_FORMAT_UINT48, /* 0x09 uint48 */
  194. GATT_FORMAT_UINT64, /* 0x0a uint64 */
  195. GATT_FORMAT_UINT128, /* 0x0B uint128 */
  196. GATT_FORMAT_SINT8, /* 0x0C signed 8 bit integer */
  197. GATT_FORMAT_SINT12, /* 0x0D signed 12 bit integer */
  198. GATT_FORMAT_SINT16, /* 0x0E signed 16 bit integer */
  199. GATT_FORMAT_SINT24, /* 0x0F signed 24 bit integer */
  200. GATT_FORMAT_SINT32, /* 0x10 signed 32 bit integer */
  201. GATT_FORMAT_SINT48, /* 0x11 signed 48 bit integer */
  202. GATT_FORMAT_SINT64, /* 0x12 signed 64 bit integer */
  203. GATT_FORMAT_SINT128, /* 0x13 signed 128 bit integer */
  204. GATT_FORMAT_FLOAT32, /* 0x14 float 32 */
  205. GATT_FORMAT_FLOAT64, /* 0x15 float 64*/
  206. GATT_FORMAT_SFLOAT, /* 0x16 IEEE-11073 16 bit SFLOAT */
  207. GATT_FORMAT_FLOAT, /* 0x17 IEEE-11073 32 bit SFLOAT */
  208. GATT_FORMAT_DUINT16, /* 0x18 IEEE-20601 format */
  209. GATT_FORMAT_UTF8S, /* 0x19 UTF-8 string */
  210. GATT_FORMAT_UTF16S, /* 0x1a UTF-16 string */
  211. GATT_FORMAT_STRUCT, /* 0x1b Opaque structure*/
  212. GATT_FORMAT_MAX /* 0x1c or above reserved */
  213. };
  214. typedef UINT8 tGATT_FORMAT;
  215. /* Characteristic Presentation Format Descriptor value
  216. */
  217. typedef struct {
  218. UINT16 unit; /* as UUID defined by SIG */
  219. UINT16 descr; /* as UUID as defined by SIG */
  220. tGATT_FORMAT format;
  221. INT8 exp;
  222. UINT8 name_spc; /* The name space of the description */
  223. } tGATT_CHAR_PRES;
  224. /* Characteristic Report reference Descriptor format
  225. */
  226. typedef struct {
  227. UINT8 rpt_id; /* report ID */
  228. UINT8 rpt_type; /* report type */
  229. } tGATT_CHAR_RPT_REF;
  230. #define GATT_VALID_RANGE_MAX_SIZE 16
  231. typedef struct {
  232. UINT8 format;
  233. UINT16 len;
  234. UINT8 lower_range[GATT_VALID_RANGE_MAX_SIZE]; /* in little endian format */
  235. UINT8 upper_range[GATT_VALID_RANGE_MAX_SIZE];
  236. } tGATT_VALID_RANGE;
  237. /* Characteristic Aggregate Format attribute value
  238. */
  239. #define GATT_AGGR_HANDLE_NUM_MAX 10
  240. typedef struct {
  241. UINT8 num_handle;
  242. UINT16 handle_list[GATT_AGGR_HANDLE_NUM_MAX];
  243. } tGATT_CHAR_AGGRE;
  244. /* Characteristic descriptor: Extended Properties value
  245. */
  246. #define GATT_CHAR_BIT_REL_WRITE 0x0001 /* permits reliable writes of the Characteristic Value */
  247. #define GATT_CHAR_BIT_WRITE_AUX 0x0002 /* permits writes to the characteristic descriptor */
  248. /* characteristic descriptor: client configuration value
  249. */
  250. #define GATT_CLT_CONFIG_NONE 0x0000
  251. #define GATT_CLT_CONFIG_NOTIFICATION 0x0001
  252. #define GATT_CLT_CONFIG_INDICATION 0x0002
  253. typedef UINT16 tGATT_CLT_CHAR_CONFIG;
  254. /* characteristic descriptor: server configuration value
  255. */
  256. #define GATT_SVR_CONFIG_NONE 0x0000
  257. #define GATT_SVR_CONFIG_BROADCAST 0x0001
  258. typedef UINT16 tGATT_SVR_CHAR_CONFIG;
  259. /* Characteristic descriptor: Extended Properties value
  260. */
  261. #define GATT_CHAR_BIT_REL_WRITE 0x0001 /* permits reliable writes of the Characteristic Value */
  262. #define GATT_CHAR_BIT_WRITE_AUX 0x0002 /* permits writes to the characteristic descriptor */
  263. /* authentication requirement
  264. */
  265. #define GATT_AUTH_REQ_NONE 0
  266. #define GATT_AUTH_REQ_NO_MITM 1 /* unauthenticated encryption */
  267. #define GATT_AUTH_REQ_MITM 2 /* authenticated encryption */
  268. #define GATT_AUTH_REQ_SIGNED_NO_MITM 3
  269. #define GATT_AUTH_REQ_SIGNED_MITM 4
  270. typedef UINT8 tGATT_AUTH_REQ;
  271. /* Attribute Value structure
  272. */
  273. typedef struct {
  274. UINT16 conn_id;
  275. UINT16 handle; /* attribute handle */
  276. UINT16 offset; /* attribute value offset, if no offset is needed for the command, ignore it */
  277. UINT16 len; /* length of attribute value */
  278. tGATT_AUTH_REQ auth_req; /* authentication request */
  279. UINT8 value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */
  280. } tGATT_VALUE;
  281. typedef struct{
  282. UINT16 attr_max_len;
  283. UINT16 attr_len;
  284. UINT8 *attr_val;
  285. }tGATT_ATTR_VAL;
  286. typedef struct{
  287. uint8_t auto_rsp;
  288. }tGATTS_ATTR_CONTROL;
  289. /* Mask for gatt server attribute */
  290. #define GATT_ATTR_VALUE_ALLOCATED 0x01
  291. typedef UINT8 tGATT_ATTR_MASK;
  292. /* Union of the event data which is used in the server respond API to carry the server response information
  293. */
  294. typedef union {
  295. /* data type member event */
  296. tGATT_VALUE attr_value; /* READ, HANDLE_VALUE_IND, PREPARE_WRITE */
  297. /* READ_BLOB, READ_BY_TYPE */
  298. UINT16 handle; /* WRITE, WRITE_BLOB */
  299. } tGATTS_RSP;
  300. /* Transports for the primary service */
  301. #define GATT_TRANSPORT_LE BT_TRANSPORT_LE
  302. #define GATT_TRANSPORT_BR_EDR BT_TRANSPORT_BR_EDR
  303. #define GATT_TRANSPORT_LE_BR_EDR (BT_TRANSPORT_LE|BT_TRANSPORT_BR_EDR)
  304. typedef UINT8 tGATT_TRANSPORT;
  305. #define GATT_PREP_WRITE_CANCEL 0x00
  306. #define GATT_PREP_WRITE_EXEC 0x01
  307. typedef UINT8 tGATT_EXEC_FLAG;
  308. /* read request always based on UUID */
  309. typedef struct {
  310. UINT16 handle;
  311. UINT16 offset;
  312. BOOLEAN is_long;
  313. BOOLEAN need_rsp;
  314. } tGATT_READ_REQ;
  315. /* write request data */
  316. typedef struct {
  317. UINT16 handle; /* attribute handle */
  318. UINT16 offset; /* attribute value offset, if no offset is needed for the command, ignore it */
  319. UINT16 len; /* length of attribute value */
  320. UINT8 value[GATT_MAX_ATTR_LEN]; /* the actual attribute value */
  321. BOOLEAN need_rsp; /* need write response */
  322. BOOLEAN is_prep; /* is prepare write */
  323. } tGATT_WRITE_REQ;
  324. /* callback data for server access request from client */
  325. typedef union {
  326. tGATT_READ_REQ read_req; /* read request, read by Type, read blob */
  327. tGATT_WRITE_REQ write_req; /* write */
  328. /* prepare write */
  329. /* write blob */
  330. UINT16 handle; /* handle value confirmation */
  331. UINT16 mtu; /* MTU exchange request */
  332. tGATT_EXEC_FLAG exec_write; /* execute write */
  333. } tGATTS_DATA;
  334. typedef UINT8 tGATT_SERV_IF; /* GATT Service Interface */
  335. enum {
  336. GATTS_REQ_TYPE_READ = 1, /* Attribute read request */
  337. GATTS_REQ_TYPE_WRITE, /* Attribute write request */
  338. GATTS_REQ_TYPE_WRITE_EXEC, /* Execute write */
  339. GATTS_REQ_TYPE_MTU, /* MTU exchange information */
  340. GATTS_REQ_TYPE_CONF /* handle value confirmation */
  341. };
  342. typedef UINT8 tGATTS_REQ_TYPE;
  343. /* Client Used Data Structure
  344. */
  345. /* definition of different discovery types */
  346. enum {
  347. GATT_DISC_SRVC_ALL = 1, /* discover all services */
  348. GATT_DISC_SRVC_BY_UUID, /* discover service of a special type */
  349. GATT_DISC_INC_SRVC, /* discover the included service within a service */
  350. GATT_DISC_CHAR, /* discover characteristics of a service with/without type requirement */
  351. GATT_DISC_CHAR_DSCPT, /* discover characteristic descriptors of a character */
  352. GATT_DISC_MAX /* maximnun discover type */
  353. };
  354. typedef UINT8 tGATT_DISC_TYPE;
  355. /* Discover parameters of different discovery types
  356. */
  357. typedef struct {
  358. tBT_UUID service;
  359. UINT16 s_handle;
  360. UINT16 e_handle;
  361. } tGATT_DISC_PARAM;
  362. /* GATT read type enumeration
  363. */
  364. enum {
  365. GATT_READ_BY_TYPE = 1,
  366. GATT_READ_BY_HANDLE,
  367. GATT_READ_MULTIPLE,
  368. GATT_READ_CHAR_VALUE,
  369. GATT_READ_PARTIAL,
  370. GATT_READ_MAX
  371. };
  372. typedef UINT8 tGATT_READ_TYPE;
  373. /* Read By Type Request (GATT_READ_BY_TYPE) Data
  374. */
  375. typedef struct {
  376. tGATT_AUTH_REQ auth_req;
  377. UINT16 s_handle;
  378. UINT16 e_handle;
  379. tBT_UUID uuid;
  380. } tGATT_READ_BY_TYPE;
  381. /* GATT_READ_MULTIPLE request data
  382. */
  383. #define GATT_MAX_READ_MULTI_HANDLES 10 /* Max attributes to read in one request */
  384. typedef struct {
  385. tGATT_AUTH_REQ auth_req;
  386. UINT16 num_handles; /* number of handles to read */
  387. UINT16 handles[GATT_MAX_READ_MULTI_HANDLES]; /* handles list to be read */
  388. } tGATT_READ_MULTI;
  389. /* Read By Handle Request (GATT_READ_BY_HANDLE) data */
  390. typedef struct {
  391. tGATT_AUTH_REQ auth_req;
  392. UINT16 handle;
  393. } tGATT_READ_BY_HANDLE;
  394. /* READ_BT_HANDLE_Request data */
  395. typedef struct {
  396. tGATT_AUTH_REQ auth_req;
  397. UINT16 handle;
  398. UINT16 offset;
  399. } tGATT_READ_PARTIAL;
  400. /* Read Request Data
  401. */
  402. typedef union {
  403. tGATT_READ_BY_TYPE service;
  404. tGATT_READ_BY_TYPE char_type; /* characteristic type */
  405. tGATT_READ_MULTI read_multiple;
  406. tGATT_READ_BY_HANDLE by_handle;
  407. tGATT_READ_PARTIAL partial;
  408. } tGATT_READ_PARAM;
  409. /* GATT write type enumeration */
  410. enum {
  411. GATT_WRITE_NO_RSP = 1,
  412. GATT_WRITE ,
  413. GATT_WRITE_PREPARE
  414. };
  415. typedef UINT8 tGATT_WRITE_TYPE;
  416. /* Client Operation Complete Callback Data
  417. */
  418. typedef union {
  419. tGATT_VALUE att_value;
  420. UINT16 mtu;
  421. UINT16 handle;
  422. } tGATT_CL_COMPLETE;
  423. /* GATT client operation type, used in client callback function
  424. */
  425. #define GATTC_OPTYPE_NONE 0
  426. #define GATTC_OPTYPE_DISCOVERY 1
  427. #define GATTC_OPTYPE_READ 2
  428. #define GATTC_OPTYPE_WRITE 3
  429. #define GATTC_OPTYPE_EXE_WRITE 4
  430. #define GATTC_OPTYPE_CONFIG 5
  431. #define GATTC_OPTYPE_NOTIFICATION 6
  432. #define GATTC_OPTYPE_INDICATION 7
  433. typedef UINT8 tGATTC_OPTYPE;
  434. /* characteristic declaration
  435. */
  436. typedef struct {
  437. tGATT_CHAR_PROP char_prop; /* characteristic properties */
  438. UINT16 val_handle; /* characteristic value attribute handle */
  439. tBT_UUID char_uuid; /* characteristic UUID type */
  440. } tGATT_CHAR_DCLR_VAL;
  441. /* primary service group data
  442. */
  443. typedef struct {
  444. UINT16 e_handle; /* ending handle of the group */
  445. tBT_UUID service_type; /* group type */
  446. } tGATT_GROUP_VALUE;
  447. /* included service attribute value
  448. */
  449. typedef struct {
  450. tBT_UUID service_type; /* included service UUID */
  451. UINT16 s_handle; /* starting handle */
  452. UINT16 e_handle; /* ending handle */
  453. } tGATT_INCL_SRVC;
  454. typedef union {
  455. tGATT_INCL_SRVC incl_service; /* include service value */
  456. tGATT_GROUP_VALUE group_value; /* Service UUID type.
  457. This field is used with GATT_DISC_SRVC_ALL
  458. or GATT_DISC_SRVC_BY_UUID
  459. type of discovery result callback. */
  460. UINT16 handle; /* When used with GATT_DISC_INC_SRVC type discovery result,
  461. it is the included service starting handle.*/
  462. tGATT_CHAR_DCLR_VAL dclr_value; /* Characteristic declaration value.
  463. This field is used with GATT_DISC_CHAR type discovery.*/
  464. } tGATT_DISC_VALUE;
  465. /* discover result record
  466. */
  467. typedef struct {
  468. tBT_UUID type;
  469. UINT16 handle;
  470. tGATT_DISC_VALUE value;
  471. } tGATT_DISC_RES;
  472. #define GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP 0 /* start a idle timer for this duration
  473. when no application need to use the link */
  474. #define GATT_LINK_NO_IDLE_TIMEOUT 0xFFFF
  475. #define GATT_INVALID_ACL_HANDLE 0xFFFF
  476. /* discover result callback function */
  477. typedef void (tGATT_DISC_RES_CB) (UINT16 conn_id, tGATT_DISC_TYPE disc_type,
  478. tGATT_DISC_RES *p_data);
  479. /* discover complete callback function */
  480. typedef void (tGATT_DISC_CMPL_CB) (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status);
  481. /* Define a callback function for when read/write/disc/config operation is completed. */
  482. typedef void (tGATT_CMPL_CBACK) (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status,
  483. tGATT_CL_COMPLETE *p_data);
  484. /* Define a callback function when an initialized connection is established. */
  485. typedef void (tGATT_CONN_CBACK) (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, BOOLEAN connected,
  486. tGATT_DISCONN_REASON reason, tBT_TRANSPORT transport);
  487. /* attribute request callback for ATT server */
  488. typedef void (tGATT_REQ_CBACK )(UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE type,
  489. tGATTS_DATA *p_data);
  490. /* channel congestion/uncongestion callback */
  491. typedef void (tGATT_CONGESTION_CBACK )(UINT16 conn_id, BOOLEAN congested);
  492. /* Define a callback function when encryption is established. */
  493. typedef void (tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, BD_ADDR bda);
  494. /* Define the structure that applications use to register with
  495. ** GATT. This structure includes callback functions. All functions
  496. ** MUST be provided.
  497. */
  498. typedef struct {
  499. tGATT_CONN_CBACK *p_conn_cb;
  500. tGATT_CMPL_CBACK *p_cmpl_cb;
  501. tGATT_DISC_RES_CB *p_disc_res_cb;
  502. tGATT_DISC_CMPL_CB *p_disc_cmpl_cb;
  503. tGATT_REQ_CBACK *p_req_cb;
  504. tGATT_ENC_CMPL_CB *p_enc_cmpl_cb;
  505. tGATT_CONGESTION_CBACK *p_congestion_cb;
  506. } tGATT_CBACK;
  507. /*********************** Start Handle Management Definitions **********************
  508. */
  509. typedef struct {
  510. tBT_UUID app_uuid128;
  511. tBT_UUID svc_uuid;
  512. UINT16 svc_inst;
  513. UINT16 s_handle;
  514. UINT16 e_handle;
  515. BOOLEAN is_primary; /* primary service or secondary */
  516. } tGATTS_HNDL_RANGE;
  517. #define GATTS_SRV_CHG_CMD_ADD_CLIENT 1
  518. #define GATTS_SRV_CHG_CMD_UPDATE_CLIENT 2
  519. #define GATTS_SRV_CHG_CMD_REMOVE_CLIENT 3
  520. #define GATTS_SRV_CHG_CMD_READ_NUM_CLENTS 4
  521. #define GATTS_SRV_CHG_CMD_READ_CLENT 5
  522. typedef UINT8 tGATTS_SRV_CHG_CMD;
  523. typedef struct {
  524. BD_ADDR bda;
  525. BOOLEAN srv_changed;
  526. } tGATTS_SRV_CHG;
  527. typedef union {
  528. tGATTS_SRV_CHG srv_chg;
  529. UINT8 client_read_index; /* only used for sequential reading client srv chg info */
  530. } tGATTS_SRV_CHG_REQ;
  531. typedef union {
  532. tGATTS_SRV_CHG srv_chg;
  533. UINT8 num_clients;
  534. } tGATTS_SRV_CHG_RSP;
  535. typedef struct {
  536. tGATTS_HNDL_RANGE *p_new_srv_start;
  537. } tGATTS_PENDING_NEW_SRV_START;
  538. /* Attribute server handle ranges NV storage callback functions
  539. */
  540. typedef void (tGATTS_NV_SAVE_CBACK)(BOOLEAN is_saved, tGATTS_HNDL_RANGE *p_hndl_range);
  541. typedef BOOLEAN (tGATTS_NV_SRV_CHG_CBACK)(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ *p_req,
  542. tGATTS_SRV_CHG_RSP *p_rsp);
  543. typedef struct {
  544. tGATTS_NV_SAVE_CBACK *p_nv_save_callback;
  545. tGATTS_NV_SRV_CHG_CBACK *p_srv_chg_callback;
  546. } tGATT_APPL_INFO;
  547. /*
  548. *********************** End Handle Management Definitions **********************/
  549. /*****************************************************************************
  550. ** External Function Declarations
  551. *****************************************************************************/
  552. #ifdef __cplusplus
  553. extern "C"
  554. {
  555. #endif
  556. /*******************************************************************************
  557. **
  558. ** Function GATT_SetTraceLevel
  559. **
  560. ** Description This function sets the trace level. If called with
  561. ** a value of 0xFF, it simply returns the current trace level.
  562. **
  563. ** Returns The new or current trace level
  564. **
  565. *******************************************************************************/
  566. extern UINT8 GATT_SetTraceLevel (UINT8 new_level);
  567. /*******************************************************************************/
  568. /* GATT Profile API Functions */
  569. /*******************************************************************************/
  570. /* GATT Profile Server Functions */
  571. /*******************************************************************************/
  572. /*******************************************************************************
  573. **
  574. ** Function GATTS_AddHandleRange
  575. **
  576. ** Description This function add the allocated handles range for the specifed
  577. ** application UUID, service UUID and service instance
  578. **
  579. ** Parameter p_hndl_range: pointer to allocated handles information
  580. **
  581. ** Returns TRUE if handle range is added successfully; otherwise FALSE.
  582. **
  583. *******************************************************************************/
  584. extern BOOLEAN GATTS_AddHandleRange(tGATTS_HNDL_RANGE *p_hndl_range);
  585. /*******************************************************************************
  586. **
  587. ** Function GATTS_NVRegister
  588. **
  589. ** Description Application manager calls this function to register for
  590. ** NV save callback function. There can be one and only one
  591. ** NV save callback function.
  592. **
  593. ** Parameter p_cb_info : callback informaiton
  594. **
  595. ** Returns TRUE if registered OK, else FALSE
  596. **
  597. *******************************************************************************/
  598. extern BOOLEAN GATTS_NVRegister (const tGATT_APPL_INFO *p_cb_info);
  599. /*******************************************************************************
  600. **
  601. ** Function GATTS_CreateService
  602. **
  603. ** Description This function is called to reserve a block of handles for a service.
  604. **
  605. ** *** It should be called only once per service instance ***
  606. **
  607. ** Parameter gatt_if : application if
  608. ** p_svc_uuid : service UUID
  609. ** svc_inst : instance of the service inside the application
  610. ** num_handles : number of handles needed by the service.
  611. ** is_pri : is a primary service or not.
  612. **
  613. ** Returns service handle if successful, otherwise 0.
  614. **
  615. *******************************************************************************/
  616. extern UINT16 GATTS_CreateService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid,
  617. UINT16 svc_inst, UINT16 num_handles, BOOLEAN is_pri);
  618. /*******************************************************************************
  619. **
  620. ** Function GATTS_AddIncludeService
  621. **
  622. ** Description This function is called to add an included service.
  623. **
  624. ** Parameter service_handle : To which service this included service is added to.
  625. ** include_svc_handle : included service handle.
  626. **
  627. ** Returns included service attribute handle. If 0, add included service
  628. ** fail.
  629. **
  630. *******************************************************************************/
  631. extern UINT16 GATTS_AddIncludeService (UINT16 service_handle,
  632. UINT16 include_svc_handle);
  633. /*******************************************************************************
  634. **
  635. ** Function GATTS_AddCharacteristic
  636. **
  637. ** Description This function is called to add a characteristic into a service.
  638. ** It will add a characteristic declaration and characteristic
  639. ** value declaration into the service database identified by the
  640. ** service handle.
  641. **
  642. ** Parameter service_handle : To which service this included service is added to.
  643. ** char_uuid : Characteristic UUID.
  644. ** perm : Characteristic value declaration attribute permission.
  645. ** property : Characteristic Properties
  646. **
  647. ** Returns Characteristic value declaration attribute handle. 0 if add
  648. ** characteristic failed.
  649. **
  650. *******************************************************************************/
  651. extern UINT16 GATTS_AddCharacteristic (UINT16 service_handle, tBT_UUID *p_char_uuid,
  652. tGATT_PERM perm, tGATT_CHAR_PROP property,
  653. tGATT_ATTR_VAL *attr_val, tGATTS_ATTR_CONTROL *control);
  654. /*******************************************************************************
  655. **
  656. ** Function GATTS_AddCharDescriptor
  657. **
  658. ** Description This function is called to add a characteristic descriptor
  659. ** into a service database. Add descriptor should follow add char
  660. ** to which it belongs, and next add char should be done only
  661. ** after all add descriptors for the previous char.
  662. **
  663. ** Parameter service_handle : To which service this characteristic descriptor
  664. ** is added to.
  665. ** perm : Characteristic value declaration attribute
  666. ** permission.
  667. ** p_descr_uuid : Characteristic descriptor UUID.
  668. **
  669. ** Returns Characteristic descriptor attribute handle. 0 if add
  670. ** characteristic descriptor failed.
  671. **
  672. *******************************************************************************/
  673. extern UINT16 GATTS_AddCharDescriptor (UINT16 service_handle, tGATT_PERM perm,
  674. tBT_UUID *p_descr_uuid, tGATT_ATTR_VAL *attr_val,
  675. tGATTS_ATTR_CONTROL *control);
  676. /*******************************************************************************
  677. **
  678. ** Function GATTS_DeleteService
  679. **
  680. ** Description This function is called to delete a service.
  681. **
  682. ** Parameter gatt_if : application interface
  683. ** p_svc_uuid : service UUID
  684. ** svc_inst : instance of the service inside the application
  685. **
  686. ** Returns TRUE if operation succeed, FALSE if handle block was not found.
  687. **
  688. *******************************************************************************/
  689. extern BOOLEAN GATTS_DeleteService (tGATT_IF gatt_if, tBT_UUID *p_svc_uuid,
  690. UINT16 svc_inst);
  691. /*******************************************************************************
  692. **
  693. ** Function GATTS_StartService
  694. **
  695. ** Description This function is called to start a service with GATT
  696. **
  697. ** Parameter gatt_if : service handle.
  698. ** p_cback : application service callback functions.
  699. ** sup_transport : supported transport(s) for this primary service
  700. **
  701. ** return GATT_SUCCESS if successfully started; otherwise error code.
  702. **
  703. *******************************************************************************/
  704. extern tGATT_STATUS GATTS_StartService (tGATT_IF gatt_if, UINT16 service_handle,
  705. tGATT_TRANSPORT sup_transport);
  706. /*******************************************************************************
  707. **
  708. ** Function GATTS_StopService
  709. **
  710. ** Description This function is called to stop a service
  711. **
  712. ** Parameter service_handle : this is the start handle of a service
  713. **
  714. ** Returns None.
  715. **
  716. *******************************************************************************/
  717. extern void GATTS_StopService (UINT16 service_handle);
  718. /*******************************************************************************
  719. **
  720. ** Function GATTs_HandleValueIndication
  721. **
  722. ** Description This function sends a handle value indication to a client.
  723. **
  724. ** Parameter conn_id: connection identifier.
  725. ** attr_handle: Attribute handle of this handle value indication.
  726. ** val_len: Length of the indicated attribute value.
  727. ** p_val: Pointer to the indicated attribute value data.
  728. **
  729. ** Returns GATT_SUCCESS if successfully sent or queued; otherwise error code.
  730. **
  731. *******************************************************************************/
  732. extern tGATT_STATUS GATTS_HandleValueIndication (UINT16 conn_id,
  733. UINT16 attr_handle,
  734. UINT16 val_len, UINT8 *p_val);
  735. /*******************************************************************************
  736. **
  737. ** Function GATTS_HandleValueNotification
  738. **
  739. ** Description This function sends a handle value notification to a client.
  740. **
  741. ** Parameter conn_id: connection identifier.
  742. ** attr_handle: Attribute handle of this handle value indication.
  743. ** val_len: Length of the indicated attribute value.
  744. ** p_val: Pointer to the indicated attribute value data.
  745. **
  746. ** Returns GATT_SUCCESS if successfully sent; otherwise error code.
  747. **
  748. *******************************************************************************/
  749. extern tGATT_STATUS GATTS_HandleValueNotification (UINT16 conn_id, UINT16 attr_handle,
  750. UINT16 val_len, UINT8 *p_val);
  751. /*******************************************************************************
  752. **
  753. ** Function GATTS_SendRsp
  754. **
  755. ** Description This function sends the server response to client.
  756. **
  757. ** Parameter conn_id: connection identifier.
  758. ** trans_id: transaction id
  759. ** status: response status
  760. ** p_msg: pointer to message parameters structure.
  761. **
  762. ** Returns GATT_SUCCESS if successfully sent; otherwise error code.
  763. **
  764. *******************************************************************************/
  765. extern tGATT_STATUS GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
  766. tGATT_STATUS status, tGATTS_RSP *p_msg);
  767. /*******************************************************************************
  768. **
  769. ** Function GATTS_SetAttributeValue
  770. **
  771. ** Description This function sends to set the attribute value .
  772. **
  773. ** Parameter attr_handle:the attribute handle
  774. ** length: the attribute length
  775. ** value: the value to be set to the attribute in the database
  776. **
  777. ** Returns GATT_SUCCESS if successfully sent; otherwise error code.
  778. **
  779. *******************************************************************************/
  780. tGATT_STATUS GATTS_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value);
  781. /*******************************************************************************
  782. **
  783. ** Function GATTS_GetAttributeValue
  784. **
  785. ** Description This function sends to set the attribute value .
  786. **
  787. ** Parameter attr_handle: the attribute handle
  788. ** length:the attribute value length in the database
  789. ** value: the attribute value out put
  790. **
  791. ** Returns GATT_SUCCESS if successfully sent; otherwise error code.
  792. **
  793. *******************************************************************************/
  794. tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value);
  795. /*******************************************************************************/
  796. /* GATT Profile Client Functions */
  797. /*******************************************************************************/
  798. /*******************************************************************************
  799. **
  800. ** Function GATTC_ConfigureMTU
  801. **
  802. ** Description This function is called to configure the ATT MTU size for
  803. ** a connection on an LE transport.
  804. **
  805. ** Parameters conn_id: connection identifier.
  806. ** mtu - attribute MTU size..
  807. **
  808. ** Returns GATT_SUCCESS if command started successfully.
  809. **
  810. *******************************************************************************/
  811. extern tGATT_STATUS GATTC_ConfigureMTU (UINT16 conn_id);
  812. /*******************************************************************************
  813. **
  814. ** Function GATTC_Discover
  815. **
  816. ** Description This function is called to do a discovery procedure on ATT server.
  817. **
  818. ** Parameters conn_id: connection identifier.
  819. ** disc_type:discovery type.
  820. ** p_param: parameters of discovery requirement.
  821. **
  822. ** Returns GATT_SUCCESS if command received/sent successfully.
  823. **
  824. *******************************************************************************/
  825. extern tGATT_STATUS GATTC_Discover (UINT16 conn_id,
  826. tGATT_DISC_TYPE disc_type,
  827. tGATT_DISC_PARAM *p_param );
  828. /*******************************************************************************
  829. **
  830. ** Function GATTC_Read
  831. **
  832. ** Description This function is called to read the value of an attribute from
  833. ** the server.
  834. **
  835. ** Parameters conn_id: connection identifier.
  836. ** type - attribute read type.
  837. ** p_read - read operation parameters.
  838. **
  839. ** Returns GATT_SUCCESS if command started successfully.
  840. **
  841. *******************************************************************************/
  842. extern tGATT_STATUS GATTC_Read (UINT16 conn_id, tGATT_READ_TYPE type,
  843. tGATT_READ_PARAM *p_read);
  844. /*******************************************************************************
  845. **
  846. ** Function GATTC_Write
  847. **
  848. ** Description This function is called to read the value of an attribute from
  849. ** the server.
  850. **
  851. ** Parameters conn_id: connection identifier.
  852. ** type - attribute write type.
  853. ** p_write - write operation parameters.
  854. **
  855. ** Returns GATT_SUCCESS if command started successfully.
  856. **
  857. *******************************************************************************/
  858. extern tGATT_STATUS GATTC_Write (UINT16 conn_id, tGATT_WRITE_TYPE type,
  859. tGATT_VALUE *p_write);
  860. /*******************************************************************************
  861. **
  862. ** Function GATTC_ExecuteWrite
  863. **
  864. ** Description This function is called to send an Execute write request to
  865. ** the server.
  866. **
  867. ** Parameters conn_id: connection identifier.
  868. ** is_execute - to execute or cancel the prepare write request(s)
  869. **
  870. ** Returns GATT_SUCCESS if command started successfully.
  871. **
  872. *******************************************************************************/
  873. extern tGATT_STATUS GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute);
  874. /*******************************************************************************
  875. **
  876. ** Function GATTC_SendHandleValueConfirm
  877. **
  878. ** Description This function is called to send a handle value confirmation
  879. ** as response to a handle value notification from server.
  880. **
  881. ** Parameters conn_id: connection identifier.
  882. ** handle: the handle of the attribute confirmation.
  883. **
  884. ** Returns GATT_SUCCESS if command started successfully.
  885. **
  886. *******************************************************************************/
  887. extern tGATT_STATUS GATTC_SendHandleValueConfirm (UINT16 conn_id, UINT16 handle);
  888. /*******************************************************************************
  889. **
  890. ** Function GATT_SetIdleTimeout
  891. **
  892. ** Description This function (common to both client and server) sets the idle
  893. ** timeout for a tansport connection
  894. **
  895. ** Parameter bd_addr: target device bd address.
  896. ** idle_tout: timeout value in seconds.
  897. ** transport: transport option.
  898. **
  899. ** Returns void
  900. **
  901. *******************************************************************************/
  902. extern void GATT_SetIdleTimeout (BD_ADDR bd_addr, UINT16 idle_tout,
  903. tGATT_TRANSPORT transport);
  904. /*******************************************************************************
  905. **
  906. ** Function GATT_Register
  907. **
  908. ** Description This function is called to register an application
  909. ** with GATT
  910. **
  911. ** Parameter p_app_uuid128: Application UUID
  912. ** p_cb_info: callback functions.
  913. **
  914. ** Returns 0 for error, otherwise the index of the client registered with GATT
  915. **
  916. *******************************************************************************/
  917. extern tGATT_IF GATT_Register (tBT_UUID *p_app_uuid128, const tGATT_CBACK *p_cb_info);
  918. /*******************************************************************************
  919. **
  920. ** Function GATT_Deregister
  921. **
  922. ** Description This function deregistered the application from GATT.
  923. **
  924. ** Parameters gatt_if: application interface.
  925. **
  926. ** Returns None.
  927. **
  928. *******************************************************************************/
  929. extern void GATT_Deregister (tGATT_IF gatt_if);
  930. /*******************************************************************************
  931. **
  932. ** Function GATT_StartIf
  933. **
  934. ** Description This function is called after registration to start receiving
  935. ** callbacks for registered interface. Function may call back
  936. ** with connection status and queued notifications
  937. **
  938. ** Parameter gatt_if: application interface.
  939. **
  940. ** Returns None
  941. **
  942. *******************************************************************************/
  943. extern void GATT_StartIf (tGATT_IF gatt_if);
  944. /*******************************************************************************
  945. **
  946. ** Function GATT_Connect
  947. **
  948. ** Description This function initiate a connection to a remote device on GATT
  949. ** channel.
  950. **
  951. ** Parameters gatt_if: application interface
  952. ** bd_addr: peer device address.
  953. ** bd_addr_type: peer device address type.
  954. ** is_direct: is a direct connection or a background auto connection
  955. ** transport : Physical transport for GATT connection (BR/EDR or LE)
  956. **
  957. ** Returns TRUE if connection started; FALSE if connection start failure.
  958. **
  959. *******************************************************************************/
  960. extern BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, tBLE_ADDR_TYPE bd_addr_type,
  961. BOOLEAN is_direct, tBT_TRANSPORT transport);
  962. /*******************************************************************************
  963. **
  964. ** Function GATT_CancelConnect
  965. **
  966. ** Description This function terminate the connection initaition to a remote
  967. ** device on GATT channel.
  968. **
  969. ** Parameters gatt_if: client interface. If 0 used as unconditionally disconnect,
  970. ** typically used for direct connection cancellation.
  971. ** bd_addr: peer device address.
  972. ** is_direct: is a direct connection or a background auto connection
  973. **
  974. ** Returns TRUE if connection started; FALSE if connection start failure.
  975. **
  976. *******************************************************************************/
  977. extern BOOLEAN GATT_CancelConnect (tGATT_IF gatt_if, BD_ADDR bd_addr,
  978. BOOLEAN is_direct);
  979. /*******************************************************************************
  980. **
  981. ** Function GATT_Disconnect
  982. **
  983. ** Description This function disconnect the GATT channel for this registered
  984. ** application.
  985. **
  986. ** Parameters conn_id: connection identifier.
  987. **
  988. ** Returns GATT_SUCCESS if disconnected.
  989. **
  990. *******************************************************************************/
  991. extern tGATT_STATUS GATT_Disconnect (UINT16 conn_id);
  992. /*******************************************************************************
  993. **
  994. ** Function GATT_SendServiceChangeIndication
  995. **
  996. ** Description This function is to send a service change indication
  997. **
  998. ** Parameters bd_addr: peer device address.
  999. **
  1000. ** Returns status.
  1001. **
  1002. *******************************************************************************/
  1003. extern tGATT_STATUS GATT_SendServiceChangeIndication (BD_ADDR bd_addr);
  1004. /*******************************************************************************
  1005. **
  1006. ** Function GATT_GetConnectionInfor
  1007. **
  1008. ** Description This function use conn_id to find its associated BD address and application
  1009. ** interface
  1010. **
  1011. ** Parameters conn_id: connection id (input)
  1012. ** p_gatt_if: application interface (output)
  1013. ** bd_addr: peer device address. (output)
  1014. ** transport : physical transport of the GATT connection (BR/EDR or LE)
  1015. **
  1016. ** Returns TRUE the logical link information is found for conn_id
  1017. **
  1018. *******************************************************************************/
  1019. extern BOOLEAN GATT_GetConnectionInfor(UINT16 conn_id, tGATT_IF *p_gatt_if,
  1020. BD_ADDR bd_addr, tBT_TRANSPORT *p_transport);
  1021. /*******************************************************************************
  1022. **
  1023. ** Function GATT_GetConnIdIfConnected
  1024. **
  1025. ** Description This function find the conn_id if the logical link for BD address
  1026. ** and application interface is connected
  1027. **
  1028. ** Parameters gatt_if: application interface (input)
  1029. ** bd_addr: peer device address. (input)
  1030. ** p_conn_id: connection id (output)
  1031. ** transport : physical transport of the GATT connection (BR/EDR or LE)
  1032. **
  1033. ** Returns TRUE the logical link is connected
  1034. **
  1035. *******************************************************************************/
  1036. extern BOOLEAN GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr,
  1037. UINT16 *p_conn_id, tBT_TRANSPORT transport);
  1038. /*******************************************************************************
  1039. **
  1040. ** Function GATT_Listen
  1041. **
  1042. ** Description This function start or stop LE advertisement and listen for
  1043. ** connection.
  1044. **
  1045. ** Parameters gatt_if: application interface
  1046. ** p_bd_addr: listen for specific address connection, or NULL for
  1047. ** listen to all device connection.
  1048. ** start: is a direct connection or a background auto connection
  1049. **
  1050. ** Returns TRUE if advertisement is started; FALSE if adv start failure.
  1051. **
  1052. *******************************************************************************/
  1053. extern BOOLEAN GATT_Listen (tGATT_IF gatt_if, BOOLEAN start, BD_ADDR_PTR bd_addr);
  1054. /*******************************************************************************
  1055. **
  1056. ** Function GATT_ConfigServiceChangeCCC
  1057. **
  1058. ** Description Configure service change indication on remote device
  1059. **
  1060. ** Returns None.
  1061. **
  1062. *******************************************************************************/
  1063. extern void GATT_ConfigServiceChangeCCC (BD_ADDR remote_bda, BOOLEAN enable,
  1064. tBT_TRANSPORT transport);
  1065. #ifdef __cplusplus
  1066. }
  1067. #endif
  1068. #endif /* GATT_API_H */