bta_gatt_api.h 33 KB

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