ql_api_ble_gatt.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /** @file
  2. ql_api_ble_gatt.h
  3. @brief
  4. This file is used to define ble gatt for different Quectel Project.
  5. */
  6. /*================================================================
  7. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  8. Quectel Wireless Solution Proprietary and Confidential.
  9. =================================================================*/
  10. /*=================================================================
  11. EDIT HISTORY FOR MODULE
  12. This section contains comments describing changes made to the module.
  13. Notice that changes are listed in reverse chronological order.
  14. WHEN WHO WHAT, WHERE, WHY
  15. ------------ ------- -------------------------------------------------------------------------------
  16. =================================================================*/
  17. #ifndef QL_API_BLE_GATT_H
  18. #define QL_API_BLE_GATT_H
  19. #include "ql_api_common.h"
  20. #include "ql_api_bt_common.h"
  21. /*========================================================================
  22. * Variable Definition
  23. *========================================================================*/
  24. #define QL_BLE_GATT_MTU_DEFAULT_SIZE 23
  25. #define QL_BLE_GATT_MTU_MAX_SIZE 247
  26. #define QL_BLE_GATT_MTU_HEAD_SIZE 3
  27. #define QL_BLE_MAX_REMOTE_NAME_LEN 32
  28. typedef struct
  29. {
  30. unsigned char name_length; //scan name lenth
  31. unsigned char name[QL_BLE_MAX_REMOTE_NAME_LEN]; //scan name data
  32. unsigned char addr_type; //device address type
  33. ql_bt_addr_s addr; //device address
  34. unsigned char event_type; //event type
  35. unsigned char data_length; //raw data length
  36. unsigned char rssi; //rssi
  37. unsigned char raw_data[QL_BLE_ADV_SCAN_DATA_SIZE]; //scan raw data
  38. } ql_ble_scan_report_info_s;
  39. typedef struct
  40. {
  41. unsigned short conn_id;
  42. unsigned char data_type; //0:chara , 1:chara_desc
  43. unsigned short len; //max 244
  44. unsigned char *data;
  45. unsigned short uuid_s;
  46. unsigned char uuid_l[QL_BLE_LONG_UUID_SIZE];
  47. unsigned short att_handle;
  48. }ql_ble_gatt_data_s;
  49. typedef enum
  50. {
  51. QL_BLE_SERVICE_CLAER = 0,
  52. QL_BLE_SERVICE_ADD_COMPLETE,
  53. }ql_ble_service_state_e;
  54. typedef struct _ql_ble_gatt_chara_desc_data_s
  55. {
  56. unsigned short permission;
  57. ql_ble_gatt_uuid_s uuid;
  58. unsigned char *value;
  59. unsigned short value_len;
  60. struct _ql_ble_gatt_chara_desc_data_s *next;
  61. }ql_ble_gatt_chara_desc_data_s;
  62. typedef struct
  63. {
  64. unsigned short permission;
  65. ql_ble_gatt_uuid_s uuid;
  66. unsigned char *value;
  67. unsigned short value_len;
  68. }ql_ble_gatt_chara_value_data_s;
  69. typedef struct _ql_ble_gatt_chara_data_s
  70. {
  71. unsigned char property;
  72. unsigned short chara_id;
  73. ql_ble_gatt_uuid_s uuid;
  74. unsigned char *value;
  75. unsigned short value_len;
  76. ql_ble_gatt_chara_value_data_s chara_value;
  77. unsigned short desc_num;
  78. ql_ble_gatt_chara_desc_data_s *head;
  79. struct _ql_ble_gatt_chara_data_s *next;
  80. }ql_ble_gatt_chara_data_s;
  81. typedef struct _ql_ble_gatt_service_data_s
  82. {
  83. unsigned short server_id;
  84. ql_ble_gatt_uuid_s uuid;
  85. unsigned char primary;
  86. unsigned short char_num;
  87. struct _ql_ble_gatt_service_data_s *next;
  88. ql_ble_gatt_chara_data_s *head;
  89. }ql_ble_gatt_service_data_s;
  90. //ble gatt
  91. typedef struct _ql_ble_gatt_service_s
  92. {
  93. unsigned short servie_num; //服务属性数据个数,包括特征值和特征描述等
  94. ql_ble_gatt_service_data_s *head;
  95. }ql_ble_gatt_service_s;
  96. typedef enum
  97. {
  98. QL_BLE_GATT_IDLE = 0,
  99. QL_BLE_GATT_DISCOVER_SERVICE,
  100. QL_BLE_GATT_DISCOVER_INCLUDES,
  101. QL_BLE_GATT_DISCOVER_CHARACTERISTIC,
  102. QL_BLE_GATT_WRITE_CHARA_VALUE,
  103. QL_BLE_GATT_WRITE_CHARA_DESC,
  104. QL_BLE_GATT_READ_CHARA_VALUE,
  105. QL_BLE_GATT_READ_CHARA_DESC,
  106. }ql_ble_gatt_state_e;
  107. typedef enum
  108. {
  109. QL_BLE_GATT_DISCOVER_SERVICE_ALL = 0,
  110. QL_BLE_GATT_DISCOVER_SERVICE_BY_UUID,
  111. }ql_ble_gatt_discover_service_mode_e;
  112. #define QL_GATT_START_HANDLE_WITH_SYS 16
  113. #define QL_GATT_START_HANDLE_WITHOUT_SYS 1
  114. #define QL_BT_MODULE_GATT 21
  115. #define QL_ATT_PM_READABLE 0x0001
  116. #define QL_ATT_PM_WRITEABLE 0x0002
  117. #define QL_ATT_PM_R_AUTHENT_REQUIRED 0x0004
  118. #define QL_ATT_PM_R_AUTHORIZE_REQUIRED 0x0008
  119. #define QL_ATT_PM_R_ENCRYPTION_REQUIRED 0x0010
  120. #define QL_ATT_PM_R_AUTHENT_MITM_REQUERED 0x0020
  121. #define QL_ATT_PM_W_AUTHENT_REQUIRED 0x0040
  122. #define QL_ATT_PM_W_AUTHORIZE_REQUIRED 0x0080
  123. #define QL_ATT_PM_W_ENCRYPTION_REQUIRED 0x0100
  124. #define QL_ATT_PM_W_AUTHENT_MITM_REQUERED 0x0200
  125. #define QL_ATT_PM_BR_ACCESS_ONLY 0x0400
  126. #define QL_ATT_CHARA_PROP_BROADCAST 0x01
  127. #define QL_ATT_CHARA_PROP_READ 0x02
  128. #define QL_ATT_CHARA_PROP_WWP 0x04 // WWP short for "write without response"
  129. #define QL_ATT_CHARA_PROP_WRITE 0x08
  130. #define QL_ATT_CHARA_PROP_NOTIFY 0x10
  131. #define QL_ATT_CHARA_PROP_INDICATE 0x20
  132. #define QL_ATT_CHARA_PROP_ASW 0x40 // ASW short for "Authenticated signed write"
  133. #define QL_ATT_CHARA_PROP_EX_PROP 0x80
  134. //GATT Attribute Types
  135. #define QL_ATT_UUID_PRIMARY 0x2800
  136. #define QL_ATT_UUID_SECONDARY 0x2801
  137. #define QL_ATT_UUID_INCLUDE 0x2802
  138. #define QL_ATT_UUID_CHAR 0x2803
  139. #define QL_ATT_FMT_INITAL_LEN(x) ((x<<22)&0xff800000)
  140. #define QL_ATT_FMT_SHORT_UUID 0x00000001
  141. #define QL_ATT_FMT_FIXED_LENGTH 0x00000002
  142. #define QL_ATT_FMT_WRITE_NOTIFY 0x00000004
  143. #define QL_ATT_FMT_GROUPED 0x00000008
  144. #define QL_ATT_FMT_CONFIRM_NOTITY 0x00000010
  145. #define QL_ATT_FMT_APPEND_WRITE 0x00000020
  146. //GATT Characteristic Descriptors
  147. #define QL_ATT_UUID_CHAR_EXT 0x2900
  148. #define QL_ATT_UUID_CHAR_USER 0x2901
  149. #define QL_ATT_UUID_CLIENT 0x2902
  150. #define QL_ATT_UUID_SERVER 0x2903
  151. #define QL_ATT_UUID_CHAR_FORMAT 0x2904
  152. #define QL_ATT_UUID_CHAR_AGGREGATE 0x2905
  153. #define QL_ATT_UUID_EXTERNAL_REF 0x2907
  154. #define QL_ATT_UUID_REPORT_RE 0x2908
  155. #define QL_GATT_NOTIFICATION 0x14
  156. #define QL_BT_GATT_CCC_NOTIFY 0x0001
  157. #define QL_BLE_LONG_UUID_PAIR_LEN 21
  158. #define QL_BLE_SHORT_UUID_PAIR_LEN 7
  159. #define QL_BLE_CHARA_NUM_MAX 5
  160. #define QL_BLE_DESC_NUM_MAX 5
  161. #define QL_BLE_CHARA_SHORT_LEN 5
  162. #define QL_BLE_CHARA_LONG_LEN 19
  163. //error code definitions
  164. #define QL_ATT_ERR_INVALID_HANDLE 0x01 //invalid handle
  165. #define QL_ATT_ERR_READ_NOT_PERMITTED 0x02 //not has read permission
  166. #define QL_ATT_ERR_WRITE_NOT_PERMITTED 0x03 //not has write permission
  167. #define QL_ATT_ERR_INVALID_PDU 0x04 //invalid pdu
  168. #define QL_ATT_ERR_INSUFFICIENT_AUTHEN 0x05 //
  169. #define QL_ATT_ERR_REQUEST_NOT_SUPPORT 0x06 //the att request is not support
  170. #define QL_ATT_ERR_INVALID_OFFSET 0x07
  171. #define QL_ATT_ERR_INSUFFICIENT_AUTHOR 0x08
  172. #define QL_ATT_ERR_PREPARE_QUEUE_FULL 0x09
  173. #define QL_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0A
  174. #define QL_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0B
  175. #define QL_ATT_ERR_INSUFFICIENT_EK_SIZE 0x0C
  176. #define QL_ATT_ERR_INVALID_ATTRI_VALUE_LEN 0x0D
  177. #define QL_ATT_ERR_UNLIKELY_ERROR 0x0E
  178. #define QL_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0F
  179. #define QL_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10
  180. #define QL_ATT_ERR_INSUFFICIENT_RESOURCES 0x11
  181. #define QL_ATT_ERR_APPLICATION_ERROR 0x80
  182. typedef unsigned char (*ql_ble_gatt_value_change_cb_t)(void *param);
  183. typedef unsigned char (*ql_ble_gatt_value_read_cb_t)(void *param);
  184. typedef void (*ql_bt_callback)(void *ind_msg_buf, void *ctx);
  185. typedef union
  186. {
  187. unsigned short uuid_s; //16bit uudi
  188. unsigned char *uuid_l; //point to 128bit uuid,if use 16bit uuid,this must be NULL
  189. }ql_ble_gatt_uuid_u;
  190. typedef struct
  191. {
  192. unsigned short length;
  193. unsigned short permisssion;
  194. ql_ble_gatt_uuid_u uuid;
  195. unsigned int fmt;
  196. void *attValue;
  197. ql_ble_gatt_value_change_cb_t cb; //client write callback
  198. ql_ble_gatt_value_read_cb_t read_cb; //client read callback
  199. }ql_ble_gatt_element_s;
  200. typedef struct
  201. {
  202. unsigned char value[19];
  203. }ql_ble_gatt_chara_value_long_s;
  204. typedef struct
  205. {
  206. unsigned char value[5];
  207. }ql_ble_gatt_chara_def_short_s;
  208. typedef struct
  209. {
  210. unsigned short configuration_bits;
  211. unsigned short acl_handle;
  212. }ql_ble_gatt_chara_ccb_s;
  213. typedef struct
  214. {
  215. unsigned short uuid;
  216. unsigned short handle;
  217. unsigned short length;
  218. unsigned char *value;
  219. }ql_ble_gatt_chara_desc_s;
  220. typedef struct
  221. {
  222. unsigned short handle;
  223. unsigned short uuid;
  224. unsigned short value_handle;
  225. unsigned char properties;
  226. int desc_um;
  227. unsigned char *value;
  228. ql_ble_gatt_chara_desc_s *pdesc_list;
  229. }ql_ble_gatt_chara_s;
  230. typedef struct
  231. {
  232. unsigned short start_handle;
  233. unsigned short end_handle;
  234. unsigned short uuid;
  235. //unsigned char uuid_l[QL_BLE_LONG_UUID_SIZE];
  236. unsigned short char_num;
  237. ql_ble_gatt_chara_s *chara_list;
  238. } ql_blegatt_prime_service_s;
  239. typedef struct
  240. {
  241. unsigned short acl_handle;
  242. unsigned short cid;
  243. unsigned short start_handle;
  244. unsigned short end_handle;
  245. unsigned short offset;
  246. unsigned short att_value_len;//attribute value length
  247. unsigned short sent_len; //value length currently sent
  248. unsigned short mtu;
  249. unsigned char uuid[QL_BLE_LONG_UUID_SIZE];
  250. unsigned char uuid_fmt;
  251. unsigned short max_att_value_len;
  252. unsigned char *att_value;//512
  253. void *tid;
  254. unsigned char flags;//used by Execute Write Request
  255. }ql_ble_att_req_pdu_s;
  256. typedef struct
  257. {
  258. unsigned short length;
  259. unsigned char *pay_load;
  260. }ql_att_general_rsp_s;
  261. typedef struct
  262. {
  263. unsigned short acl_handle;
  264. unsigned short cid;
  265. unsigned short mtu;
  266. ql_ble_att_req_pdu_s last_req_pdu;
  267. ql_att_general_rsp_s last_rsp;
  268. ql_att_general_rsp_s last_rsp_alt;
  269. ql_att_general_rsp_s last_noti;
  270. unsigned char value_ind;
  271. unsigned char req_timer_id;
  272. }ql_ble_att_server_s;
  273. typedef struct
  274. {
  275. unsigned short handle;
  276. unsigned short value_len;
  277. unsigned short proxy_addr;
  278. ql_ble_gatt_element_s *attribute;
  279. }ql_ble_gatt_srv_write_notify_s;
  280. typedef struct
  281. {
  282. unsigned short att_handle;
  283. ql_ble_gatt_uuid_u uuid;
  284. unsigned char uuid_type;
  285. unsigned short length;
  286. unsigned short acl_handle;
  287. unsigned char *data;
  288. }ql_ble_gatt_data_info_t;
  289. typedef enum
  290. {
  291. QL_RESERVED_SERVICE_DEL = 0, //删除系统默认的GAP和GATT服务
  292. QL_RESERVED_SERVICE_KEEP, //保留系统默认的GAP和GATT服务
  293. }ql_ble_sys_service_mode_e;
  294. /*========================================================================
  295. * function Definition
  296. *========================================================================*/
  297. //以下函数用于从机(server)
  298. /*****************************************************************
  299. * Function: ql_ble_gatt_server_init
  300. *
  301. * Description:
  302. * 初始化BLE GATT从机并注册回调函数
  303. *
  304. * Parameters:
  305. * bt_cb [out] BLE GATT回调函数
  306. *
  307. * Return:ql_errcode_bt_e
  308. *
  309. *****************************************************************/
  310. ql_errcode_bt_e ql_ble_gatt_server_init(ql_bt_callback bt_cb);
  311. /*****************************************************************
  312. * Function: ql_ble_gatt_server_release
  313. *
  314. * Description:
  315. * BLE GATT从机释放资源
  316. *
  317. * Parameters:
  318. *
  319. * Return:ql_errcode_bt_e
  320. *
  321. *****************************************************************/
  322. ql_errcode_bt_e ql_ble_gatt_server_release();
  323. /*****************************************************************
  324. * Function: ql_ble_gatt_add_service
  325. *
  326. * Description:
  327. * 开始增加一个服务
  328. *
  329. * Parameters:
  330. * server_id [in] 服务ID,用来确定某一个服务
  331. * uuid [in] 服务UUID
  332. * primary [in] 服务类型,1为主要服务,其他未次要服务
  333. *
  334. * Return:ql_errcode_bt_e
  335. *
  336. *****************************************************************/
  337. ql_errcode_bt_e ql_ble_gatt_add_service(unsigned short server_id, ql_ble_gatt_uuid_s uuid, unsigned char primary);
  338. /*****************************************************************
  339. * Function: ql_ble_gatt_add_chara
  340. *
  341. * Description:
  342. * 在服务里增加一个特征
  343. *
  344. * Parameters:
  345. * server_id [in] 服务ID,特征增加到的哪个服务
  346. * chara_id [in] 特征ID
  347. * prop [in] 特征的属性,十六进制数。01:广播。02:可读。04:可写且不需要链路层应答。08:可写。
  348. * 10:通知。20:指示。40:认证签名写。80:扩展属性。
  349. * uuid [in] 特征UUID
  350. *
  351. * Return:ql_errcode_bt_e
  352. *
  353. *****************************************************************/
  354. ql_errcode_bt_e ql_ble_gatt_add_chara(unsigned short server_id, unsigned short chara_id, unsigned char prop, ql_ble_gatt_uuid_s uuid);
  355. /*****************************************************************
  356. * Function: ql_ble_gatt_add_chara_value
  357. *
  358. * Description:
  359. * 在特征里增加一个特征值
  360. *
  361. * Parameters:
  362. * server_id [in] 服务ID,特征值增加到的哪个服务
  363. * chara_id [in] 特征ID,特征值增加到的哪个特征
  364. * permission [in] 特征值的权限Bit0:可读权限。Bit1:可写权限.。Bit2:读需要认证。Bit3:读需要授权。Bit4:读需要加密。
  365. * Bit5:读需要授权认证。Bit6:写需要认证。Bit7:写需要授权。Bit8:写需要加密。Bit9:写需要授权认证。
  366. * uuid [in] 特征值UUID,与ql_ble_gatt_add_chara函数里uuid参数一致
  367. * value_len [in] 特征值数据长度
  368. * value [in] 特征值数据
  369. *
  370. * Return:ql_errcode_bt_e
  371. *
  372. *****************************************************************/
  373. ql_errcode_bt_e ql_ble_gatt_add_chara_value(unsigned short server_id, unsigned short chara_id, unsigned short permission, ql_ble_gatt_uuid_s uuid, unsigned short value_len, unsigned char *value);
  374. /*****************************************************************
  375. * Function: ql_ble_gatt_change_chara_value
  376. *
  377. * Description:
  378. * change the charcteristic value
  379. *
  380. * Parameters:
  381. * server_id [in] server ID
  382. * chara_id [in] charcteristic ID
  383. * value_len [in] value changed len
  384. * value [in] characteristic changed value
  385. *
  386. * Return:ql_errcode_bt_e
  387. *
  388. *****************************************************************/
  389. ql_errcode_bt_e ql_ble_gatt_change_chara_value(unsigned short server_id, unsigned short chara_id, unsigned short value_len, unsigned char *value);
  390. /*****************************************************************
  391. * Function: ql_ble_gatt_add_chara_value
  392. *
  393. * Description:
  394. * 在特征里增加一个特征描述,注意特征描述和特征值同属与一个特征
  395. *
  396. * Parameters:
  397. * server_id [in] 服务ID,特征描述增加到的哪个服务
  398. * chara_id [in] 特征ID,特征描述增加到的哪个特征
  399. * permission [in] 特征描述的权限Bit0:可读权限。Bit1:可写权限.。Bit2:读需要认证。Bit3:读需要授权。Bit4:读需要加密。
  400. * Bit5:读需要授权认证。Bit6:写需要认证。Bit7:写需要授权。Bit8:写需要加密。Bit9:写需要授权认证。
  401. * uuid [in] 特征描述UUID
  402. * value_len [in] 特征描述数据长度
  403. * value [in] 特征描述数据
  404. *
  405. * Return:ql_errcode_bt_e
  406. *
  407. *****************************************************************/
  408. ql_errcode_bt_e ql_ble_gatt_add_chara_desc(unsigned short server_id, unsigned short chara_id, unsigned short permission, ql_ble_gatt_uuid_s uuid, unsigned short value_len, unsigned char *value);
  409. /*****************************************************************
  410. * Function: ql_ble_gatt_add_or_clear_service_complete
  411. *
  412. * Description:
  413. * 增加服务完成,或者删除增加的服务
  414. *
  415. * Parameters:
  416. * type [in] 操作类型,0-删除服务,1-增加服务完成
  417. * mode [in] 保留系统服务模式
  418. *
  419. * Return:ql_errcode_bt_e
  420. ******************************************************************/
  421. ql_errcode_bt_e ql_ble_gatt_add_or_clear_service_complete(unsigned short type, ql_ble_sys_service_mode_e mode);
  422. /*****************************************************************
  423. * Function: ql_ble_send_notification_data
  424. *
  425. * Description:
  426. * 发送通知
  427. *
  428. * Parameters:
  429. * conn_id [in] 连接ID,建立连接时得到的连接ID
  430. * att_handle [in] 属性句柄,注意,一定要是特征值的句柄
  431. * length [in] 通知数据的长度
  432. * value [in] 通知数据
  433. *
  434. * Return:ql_errcode_bt_e
  435. ******************************************************************/
  436. ql_errcode_bt_e ql_ble_send_notification_data(unsigned short conn_id, unsigned short att_handle, unsigned short length, unsigned char *value);
  437. /*****************************************************************
  438. * Function: ql_ble_send_indication_data
  439. *
  440. * Description:
  441. * 发送指示
  442. *
  443. * Parameters:
  444. * conn_id [in] 连接ID,建立连接时得到的连接ID
  445. * att_handle [in] 属性句柄,注意,一定要是特征值的句柄
  446. * length [in] 指示数据的长度
  447. * value [in] 指示数据
  448. *
  449. * Return:ql_errcode_bt_e
  450. ******************************************************************/
  451. ql_errcode_bt_e ql_ble_send_indication_data(unsigned short conn_id, unsigned short att_handle, unsigned short length, unsigned char *value);
  452. //以下函数用于主机(client)
  453. /*****************************************************************
  454. * Function: ql_ble_gatt_client_init
  455. *
  456. * Description:
  457. * 初始化BLE GATT主机并注册回调函数
  458. *
  459. * Parameters:
  460. * bt_cb [out] BLE GATT回调函数
  461. *
  462. * Return:ql_errcode_bt_e
  463. *
  464. *****************************************************************/
  465. ql_errcode_bt_e ql_ble_gatt_client_init(ql_bt_callback bt_cb);
  466. /*****************************************************************
  467. * Function: ql_ble_gatt_client_release
  468. *
  469. * Description:
  470. * BLE GATT主机释放资源
  471. *
  472. * Parameters:
  473. *
  474. * Return:ql_errcode_bt_e
  475. *
  476. *****************************************************************/
  477. ql_errcode_bt_e ql_ble_gatt_client_release();
  478. /*****************************************************************
  479. * Function: ql_ble_gatt_discover_all_service
  480. *
  481. * Description:
  482. * 发现所有的服务
  483. *
  484. * Parameters:
  485. * conn_id [in] 连接ID,建立连接时得到的连接ID
  486. *
  487. * Return:ql_errcode_bt_e
  488. ******************************************************************/
  489. ql_errcode_bt_e ql_ble_gatt_discover_all_service(unsigned short conn_id);
  490. /*****************************************************************
  491. * Function: ql_ble_gatt_discover_by_uuid
  492. *
  493. * Description:
  494. * 发现指定UUID的服务
  495. *
  496. * Parameters:
  497. * conn_id [in] 连接ID,建立连接时得到的连接ID
  498. * uuid [in] 服务UUID
  499. *
  500. * Return:ql_errcode_bt_e
  501. ******************************************************************/
  502. ql_errcode_bt_e ql_ble_gatt_discover_by_uuid(unsigned short conn_id, ql_ble_gatt_uuid_s uuid);
  503. /*****************************************************************
  504. * Function: ql_ble_gatt_discover_all_includes
  505. *
  506. * Description:
  507. * 发现所有的引用
  508. *
  509. * Parameters:
  510. * conn_id [in] 连接ID,建立连接时得到的连接ID
  511. * start_handle [in] 开始句柄,从这个句柄开始寻找引用
  512. * end_handle [in] 结束句柄,从这个句柄结束寻找引用
  513. *
  514. * Return:ql_errcode_bt_e
  515. ******************************************************************/
  516. ql_errcode_bt_e ql_ble_gatt_discover_all_includes(unsigned short conn_id, unsigned short start_handle, unsigned short end_handle);
  517. /*****************************************************************
  518. * Function: ql_ble_gatt_discover_all_characteristic
  519. *
  520. * Description:
  521. * 发现所有的特征,start_handle和end_handle要属于同一个服务
  522. *
  523. * Parameters:
  524. * conn_id [in] 连接ID,建立连接时得到的连接ID
  525. * start_handle [in] 开始句柄,从这个句柄开始寻找特征
  526. * end_handle [in] 结束句柄,从这个句柄结束寻找特征
  527. *
  528. * Return:ql_errcode_bt_e
  529. ******************************************************************/
  530. ql_errcode_bt_e ql_ble_gatt_discover_all_characteristic(unsigned short conn_id, unsigned short start_handle, unsigned short end_handle);
  531. /*****************************************************************
  532. * Function: ql_ble_gatt_discover_chara_desc
  533. *
  534. * Description:
  535. * 发现所有的特征的特征描述,start_handle和end_handle一定要属于同一个特征的句柄
  536. *
  537. * Parameters:
  538. * conn_id [in] 连接ID,建立连接时得到的连接ID
  539. * start_handle [in] 开始句柄,从这个句柄开始寻找特征描述
  540. * end_handle [in] 结束句柄,从这个句柄结束寻找特征描述
  541. *
  542. * Return:ql_errcode_bt_e
  543. ******************************************************************/
  544. ql_errcode_bt_e ql_ble_gatt_discover_chara_desc(unsigned short conn_id, unsigned short start_handle, unsigned short end_handle);
  545. /*****************************************************************
  546. * Function: ql_ble_gatt_read_chara_value_by_uuid
  547. *
  548. * Description:
  549. * 读取指定UUID的特征值,start_handle和end_handle必须要包含一个特征值句柄
  550. *
  551. * Parameters:
  552. * conn_id [in] 连接ID,建立连接时得到的连接ID
  553. * uuid [in] 特征值UUID
  554. * start_handle [in] 开始句柄,一定要属于同一个特征的句柄
  555. * end_handle [in] 结束句柄,一定要属于同一个特征的句柄
  556. *
  557. * Return:ql_errcode_bt_e
  558. ******************************************************************/
  559. ql_errcode_bt_e ql_ble_gatt_read_chara_value_by_uuid(unsigned short conn_id, ql_ble_gatt_uuid_s uuid, unsigned short start_handle, unsigned short end_handle);
  560. /*****************************************************************
  561. * Function: ql_ble_gatt_read_chara_value_by_handle
  562. *
  563. * Description:
  564. * 读取特征值
  565. *
  566. * Parameters:
  567. * conn_id [in] 连接ID,建立连接时得到的连接ID
  568. * att_handle [in] 特征值句柄
  569. * offset [in] 偏移位置
  570. * islong [in] 长特征值标志,0-短特征值,一次可以读取完;1-长特征值,分多次读取
  571. *
  572. * Return:ql_errcode_bt_e
  573. ******************************************************************/
  574. ql_errcode_bt_e ql_ble_gatt_read_chara_value_by_handle(unsigned short conn_id, unsigned short att_handle, unsigned short offset, unsigned char islong);
  575. /*****************************************************************
  576. * Function: ql_ble_gatt_read_mul_chara_value
  577. *
  578. * Description:
  579. * 读取多个特征值
  580. *
  581. * Parameters:
  582. * conn_id [in] 连接ID,建立连接时得到的连接ID
  583. * att_handle [in] 多个特征值句柄数据
  584. * length [in] 特征值句柄数据长度
  585. *
  586. * Return:ql_errcode_bt_e
  587. ******************************************************************/
  588. ql_errcode_bt_e ql_ble_gatt_read_mul_chara_value(unsigned short conn_id, unsigned char *att_handle, unsigned char length);
  589. /*****************************************************************
  590. * Function: ql_ble_gatt_read_chara_desc
  591. *
  592. * Description:
  593. * 读取特征描述
  594. * Parameters:
  595. * conn_id [in] 连接ID,建立连接时得到的连接ID
  596. * att_handle [in] 特征描述句柄
  597. * islong [in] 特征描述为长属性数据
  598. *
  599. * Return:ql_errcode_bt_e
  600. ******************************************************************/
  601. ql_errcode_bt_e ql_ble_gatt_read_chara_desc(unsigned short conn_id, unsigned short att_handle, unsigned char islong);
  602. /*****************************************************************
  603. * Function: ql_ble_gatt_write_chara_desc
  604. *
  605. * Description:
  606. * 写入特征描述
  607. * Parameters:
  608. * conn_id [in] 连接ID,建立连接时得到的连接ID
  609. * att_handle [in] 特征描述句柄
  610. * length [in] 特征描述数据长度
  611. * value [in] 特征描述数据
  612. *
  613. * Return:ql_errcode_bt_e
  614. ******************************************************************/
  615. ql_errcode_bt_e ql_ble_gatt_write_chara_desc(unsigned short conn_id, unsigned short att_handle, unsigned short length, unsigned char *value);
  616. /*****************************************************************
  617. * Function: ql_ble_gatt_write_chara_value
  618. *
  619. * Description:
  620. * 写入特征值,链路层需要确认
  621. * Parameters:
  622. * conn_id [in] 连接ID,建立连接时得到的连接ID
  623. * att_handle [in] 特征值句柄
  624. * length [in] 特征值数据长度
  625. * value [in] 特征值数据
  626. * offset [in] 偏移位置
  627. * islong [in] 长特征值标志,0-短特征值,一次可以读取完;1-长特征值,分多次读取
  628. *
  629. * Return:ql_errcode_bt_e
  630. ******************************************************************/
  631. ql_errcode_bt_e ql_ble_gatt_write_chara_value(unsigned short conn_id, unsigned short att_handle, unsigned short length, unsigned char *value, unsigned short offset, unsigned char islong);
  632. /*****************************************************************
  633. * Function: ql_ble_gatt_write_chara_value
  634. *
  635. * Description:
  636. * 写入特征值,链路层不需要确认
  637. * Parameters:
  638. * conn_id [in] 连接ID,建立连接时得到的连接ID
  639. * att_handle [in] 特征值句柄
  640. * length [in] 特征值数据长度
  641. * value [in] 特征值数据
  642. *
  643. * Return:ql_errcode_bt_e
  644. ******************************************************************/
  645. ql_errcode_bt_e ql_ble_gatt_write_chara_value_no_rsp(unsigned short conn_id, unsigned short att_handle, unsigned short length, unsigned char *value);
  646. /*****************************************************************
  647. * Function: ql_ble_gatt_auth_device
  648. *
  649. * Description:
  650. * 授权设备
  651. * Parameters:
  652. * conn_id [in] 连接ID,建立连接时得到的连接ID
  653. * type [in] 是否授权,0:取消授权;1:授权
  654. *
  655. * Return:ql_errcode_bt_e
  656. ******************************************************************/
  657. ql_errcode_bt_e ql_ble_gatt_auth_device(unsigned short conn_id, bool type);
  658. #endif /* QL_API_BLE_GATT_H */