dis_api.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 1999-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. ** Header file for profile folder.
  21. **
  22. ********************************************************************************/
  23. #ifndef SRVC_DIS_API_H
  24. #define SRVC_DIS_API_H
  25. #include "common/bt_target.h"
  26. #include "stack/gatt_api.h"
  27. #include "stack/gattdefs.h"
  28. #include "esp_gatts_api.h"
  29. #define DIS_SUCCESS GATT_SUCCESS
  30. #define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER
  31. #define DIS_NO_RESOURCES GATT_NO_RESOURCES
  32. typedef UINT8 tDIS_STATUS;
  33. /*****************************************************************************
  34. ** Data structure for DIS
  35. *****************************************************************************/
  36. #define DIS_ATTR_SYS_ID_BIT 0x0001
  37. #define DIS_ATTR_MODEL_NUM_BIT 0x0002
  38. #define DIS_ATTR_SERIAL_NUM_BIT 0x0004
  39. #define DIS_ATTR_FW_NUM_BIT 0x0008
  40. #define DIS_ATTR_HW_NUM_BIT 0x0010
  41. #define DIS_ATTR_SW_NUM_BIT 0x0020
  42. #define DIS_ATTR_MANU_NAME_BIT 0x0040
  43. #define DIS_ATTR_IEEE_DATA_BIT 0x0080
  44. #define DIS_ATTR_PNP_ID_BIT 0x0100
  45. typedef UINT16 tDIS_ATTR_MASK;
  46. #define DIS_ATTR_ALL_MASK 0xffff
  47. typedef tDIS_ATTR_MASK tDIS_ATTR_BIT ;
  48. #define DIS_MAX_NUM_INC_SVR 0
  49. #define DIS_MAX_CHAR_NUM 9
  50. #define DIS_MAX_ATTR_NUM (DIS_MAX_CHAR_NUM * 2 + DIS_MAX_NUM_INC_SVR + 1)
  51. #ifndef DIS_ATTR_DB_SIZE
  52. #define DIS_ATTR_DB_SIZE GATT_DB_MEM_SIZE(DIS_MAX_NUM_INC_SVR, DIS_MAX_CHAR_NUM, 0)
  53. #endif
  54. #define DIS_SYSTEM_ID_SIZE 8
  55. #define DIS_PNP_ID_SIZE 7
  56. typedef struct {
  57. UINT16 uuid;
  58. UINT16 handle;
  59. } tDIS_DB_ENTRY;
  60. typedef struct {
  61. UINT16 len;
  62. UINT8 *p_data;
  63. } tDIS_STRING;
  64. typedef struct {
  65. UINT16 vendor_id;
  66. UINT16 product_id;
  67. UINT16 product_version;
  68. UINT8 vendor_id_src;
  69. } tDIS_PNP_ID;
  70. typedef union {
  71. UINT64 system_id;
  72. tDIS_PNP_ID pnp_id;
  73. tDIS_STRING data_str;
  74. } tDIS_ATTR;
  75. #define DIS_MAX_STRING_DATA 7
  76. typedef struct {
  77. UINT16 attr_mask;
  78. UINT64 system_id;
  79. tDIS_PNP_ID pnp_id;
  80. UINT8 *data_string[DIS_MAX_STRING_DATA];
  81. } tDIS_VALUE;
  82. //typedef void (tDIS_READ_CBACK)(BD_ADDR addr, tDIS_VALUE *p_dis_value);
  83. typedef struct {
  84. tDIS_DB_ENTRY dis_attr[DIS_MAX_CHAR_NUM];
  85. tDIS_VALUE dis_value;
  86. // tDIS_READ_CBACK *p_read_dis_cback;
  87. UINT16 service_handle;
  88. UINT16 max_handle;
  89. bool enabled;
  90. // UINT8 dis_read_uuid_idx;
  91. // tDIS_ATTR_MASK request_mask;
  92. } tDIS_CB;
  93. /*****************************************************************************
  94. ** Data structure used by Battery Service
  95. *****************************************************************************/
  96. #ifndef BA_MAX_INT_NUM
  97. #define BA_MAX_INT_NUM 4
  98. #endif
  99. #define BATTERY_LEVEL_SIZE 1
  100. typedef struct {
  101. BD_ADDR remote_bda;
  102. BOOLEAN need_rsp;
  103. UINT16 clt_cfg;
  104. } tBA_WRITE_DATA;
  105. #define BA_READ_CLT_CFG_REQ 1
  106. #define BA_READ_PRE_FMT_REQ 2
  107. #define BA_READ_RPT_REF_REQ 3
  108. #define BA_READ_LEVEL_REQ 4
  109. #define BA_WRITE_CLT_CFG_REQ 5
  110. typedef void (tBA_CBACK)(UINT32 trans_id, UINT16 conn_id, UINT8 app_id, UINT8 event, tBA_WRITE_DATA *p_data);
  111. #define BA_LEVEL_NOTIFY 0x01
  112. #define BA_LEVEL_PRE_FMT 0x02
  113. #define BA_LEVEL_RPT_REF 0x04
  114. typedef UINT8 tBA_LEVEL_DESCR;
  115. typedef struct {
  116. BOOLEAN is_pri;
  117. tBA_LEVEL_DESCR ba_level_descr;
  118. tGATT_TRANSPORT transport;
  119. tBA_CBACK *p_cback;
  120. } tBA_REG_INFO;
  121. typedef union {
  122. UINT8 ba_level;
  123. UINT16 clt_cfg;
  124. tGATT_CHAR_RPT_REF rpt_ref;
  125. tGATT_CHAR_PRES pres_fmt;
  126. } tBA_RSP_DATA;
  127. typedef struct {
  128. UINT8 app_id;
  129. UINT16 ba_level_hdl;
  130. UINT16 clt_cfg_hdl;
  131. UINT16 rpt_ref_hdl;
  132. UINT16 pres_fmt_hdl;
  133. tBA_CBACK *p_cback;
  134. UINT16 pending_handle;
  135. //UINT8 pending_clcb_idx;
  136. UINT8 pending_evt;
  137. } tBA_INST;
  138. typedef struct {
  139. tBA_INST battery_inst[BA_MAX_INT_NUM];
  140. UINT8 inst_id;
  141. bool enabled;
  142. } tBATTERY_CB;
  143. /*****************************************************************************
  144. ** External Function Declarations
  145. *****************************************************************************/
  146. #ifdef __cplusplus
  147. extern "C"
  148. {
  149. #endif
  150. /*****************************************************************************
  151. ** Service Engine API
  152. *****************************************************************************/
  153. /*******************************************************************************
  154. **
  155. ** Function srvc_eng_init
  156. **
  157. ** Description Initializa the GATT Service engine, register a GATT application
  158. ** as for a central service management.
  159. **
  160. *******************************************************************************/
  161. //extern tGATT_STATUS srvc_eng_init (void);
  162. /*****************************************************************************
  163. ** DIS Server Function
  164. *****************************************************************************/
  165. extern bool dis_valid_handle_range(UINT16 handle);
  166. /*******************************************************************************
  167. **
  168. ** Function DIS_Init
  169. **
  170. ** Description Initializa the Device Information Service Server.
  171. **
  172. *******************************************************************************/
  173. extern void DIS_Init (tBTA_GATTS_IF gatt_if, tDIS_ATTR_MASK dis_attr_mask);
  174. /*******************************************************************************
  175. **
  176. ** Function DIS_SrUpdate
  177. **
  178. ** Description Update the DIS server attribute values
  179. **
  180. *******************************************************************************/
  181. extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR *p_info);
  182. /*******************************************************************************
  183. **
  184. ** Function dis_AddChar
  185. **
  186. ** Description add characteristic for dis
  187. **
  188. *******************************************************************************/
  189. extern void dis_AddChar(UINT16 service_id);
  190. /*******************************************************************************
  191. ** dis_s_read_attr_value
  192. **
  193. ** Process read DIS attribute request.
  194. *******************************************************************************/
  195. extern void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value,
  196. UINT32 trans_id, UINT16 conn_id);
  197. /*****************************************************************************
  198. ** DIS Client Function
  199. *****************************************************************************/
  200. /*******************************************************************************
  201. **
  202. ** Function DIS_ReadDISInfo
  203. **
  204. ** Description Read remote device DIS information.
  205. **
  206. ** Returns void
  207. **
  208. *******************************************************************************/
  209. //extern BOOLEAN DIS_ReadDISInfo(BD_ADDR peer_bda, tDIS_READ_CBACK *p_cback,
  210. // tDIS_ATTR_MASK mask);
  211. /*******************************************************************************
  212. ** BATTERY SERVICE API
  213. *******************************************************************************/
  214. /***************************************************************
  215. **
  216. ** Function bas_register
  217. **
  218. ** Description register app for battery service
  219. **
  220. ****************************************************************/
  221. extern void bas_register(void);
  222. /***************************************************************
  223. **
  224. ** Function bas_init
  225. **
  226. ** Description register battery service
  227. **
  228. ****************************************************************/
  229. extern void bas_init(tBTA_GATTS_IF gatt_if, UINT16 app_id);
  230. /***************************************************************
  231. **
  232. ** Function bas_AddChar
  233. **
  234. ** Description add characteristic for battery service
  235. **
  236. ****************************************************************/
  237. extern void bas_AddChar(UINT16 service_id, tBT_UUID *char_uuid);
  238. /***************************************************************
  239. **
  240. ** Function bas_AddCharDescr
  241. **
  242. ** Description add descriptor for battery service if needed
  243. **
  244. ****************************************************************/
  245. extern void bas_AddCharDescr(UINT16 service_id, UINT16 attr_id);
  246. /***************************************************************
  247. **
  248. ** Function bas_service_cmpl
  249. **
  250. ** Description create battery service complete
  251. **
  252. ****************************************************************/
  253. extern void bas_service_cmpl(UINT16 service_id, tBTA_GATT_STATUS status);
  254. /*******************************************************************************
  255. **
  256. ** Function Battery_Rsp
  257. **
  258. ** Description Respond to a battery service request
  259. **
  260. *******************************************************************************/
  261. extern void Battery_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id,
  262. tGATT_STATUS st, UINT8 event, tBA_RSP_DATA *p_rsp);
  263. /*******************************************************************************
  264. **
  265. ** Function Battery_Notify
  266. **
  267. ** Description Send battery level notification
  268. **
  269. *******************************************************************************/
  270. extern void Battery_Notify (UINT16 conn_id, UINT8 app_id, BD_ADDR remote_bda, UINT8 battery_level);
  271. /*****************************************************************************
  272. ** Function bas_s_read_attr_value
  273. **
  274. ** Description it will be called when client send a read request
  275. ******************************************************************************/
  276. extern void bas_s_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id);
  277. /*****************************************************************************
  278. ** Function bas_s_write_attr_value
  279. **
  280. ** Description it will be called when client send a write request
  281. ******************************************************************************/
  282. extern void bas_s_write_attr_value(tGATTS_DATA *p_data, UINT32 trans_id,
  283. UINT16 conn_id, BD_ADDR bd_addr);
  284. extern void gatts_server_test(void);
  285. #ifdef __cplusplus
  286. }
  287. #endif
  288. #endif