mesh_services.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /**
  2. * \file mesh_services.h
  3. *
  4. * Generic Module to handle both
  5. * - Mesh Provisioning Service :: 0x1827
  6. * - Mesh Proxy Service :: 0x1828
  7. */
  8. /*
  9. * Copyright (C) 2018. Mindtree Limited.
  10. * All rights reserved.
  11. */
  12. #ifndef _MESH_SERVICES_H
  13. #define _MESH_SERVICES_H
  14. /* ----------------------------------------------------------------------------
  15. * If building with a C++ compiler, make all of the definitions in this header
  16. * have a C binding.
  17. * ------------------------------------------------------------------------- */
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. /* ----------------------------------------------------------------------------
  23. * Include files
  24. * --------------------------------------------------------------------------*/
  25. /* Mesh OS Specific Inclusion */
  26. #include "EM_os.h"
  27. /* BLE Stack Specific Inclusion */
  28. #include "bcomdef.h"
  29. #include "OSAL.h"
  30. #include "linkdb.h"
  31. #include "att.h"
  32. #include "gatt.h"
  33. #include "gatt_uuid.h"
  34. #include "gattservapp.h"
  35. #include "gapbondmgr.h"
  36. /* ----------------------------------------------------------------------------
  37. * Defines
  38. * --------------------------------------------------------------------------*/
  39. /* Mesh GATT Bearer Related Service Assigned Numbers */
  40. #define MESH_PROV_SERVICE_UUID128 { 0x27, 0x18, 0x00, 0x00, 0x00, 0x00, \
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  42. 0x00, 0x00, 0x00, 0x00 }
  43. #define MESH_PROXY_SERVICE_UUID128 { 0x28, 0x18, 0x00, 0x00, 0x00, 0x00, \
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  45. 0x00, 0x00, 0x00, 0x00 }
  46. #define MESH_PROV_DATA_IN_UUID128 { 0xDB, 0x2A, 0x00, 0x00, 0x00, 0x00, \
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  48. 0x00, 0x00, 0x00, 0x00 }
  49. #define MESH_PROV_DATA_OUT_UUID128 { 0xDC, 0x2A, 0x00, 0x00, 0x00, 0x00, \
  50. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  51. 0x00, 0x00, 0x00, 0x00 }
  52. #define MESH_PROXY_DATA_IN_UUID128 { 0xDD, 0x2A, 0x00, 0x00, 0x00, 0x00, \
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  54. 0x00, 0x00, 0x00, 0x00 }
  55. #define MESH_PROXY_DATA_OUT_UUID128 { 0xDE, 0x2A, 0x00, 0x00, 0x00, 0x00, \
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  57. 0x00, 0x00, 0x00, 0x00 }
  58. /* 16 Bit UUID Defines */
  59. #define MESH_PROV_SERVICE_UUID 0x1827
  60. #define MESH_PROXY_SERVICE_UUID 0x1828
  61. #define MESH_PROV_DATA_IN_UUID 0x2ADB
  62. #define MESH_PROV_DATA_OUT_UUID 0x2ADC
  63. #define MESH_PROXY_DATA_IN_UUID 0x2ADD
  64. #define MESH_PROXY_DATA_OUT_UUID 0x2ADE
  65. /* Mesh GATT Bearer Serivce Characterisitic Length Definitions */
  66. #define MESH_PROV_DATA_IN_MAX_LENGTH (ATT_MTU_SIZE - 3)
  67. #define MESH_PROV_DATA_OUT_MAX_LENGTH (ATT_MTU_SIZE - 3)
  68. #define MESH_PROXY_DATA_IN_MAX_LENGTH (ATT_MTU_SIZE - 3)
  69. #define MESH_PROXY_DATA_OUT_MAX_LENGTH (ATT_MTU_SIZE - 3)
  70. enum mesh_prov_idx_att
  71. {
  72. /* Mesh Provisioning Service Primary Service Declaration */
  73. MESH_PROV_SERV_DECL = 0x00,
  74. /* Mesh Provisioning Data IN Characteristic */
  75. MESH_PROV_DATA_IN_VALUE_CHAR,
  76. MESH_PROV_DATA_IN_VALUE_VAL,
  77. /* Mesh Provisioning Data OUT Characteristic */
  78. MESH_PROV_DATA_OUT_VALUE_CHAR,
  79. MESH_PROV_DATA_OUT_VALUE_VAL,
  80. MESH_PROV_DATA_OUT_VALUE_CCC,
  81. /* Max number of characteristics */
  82. MESH_PROV_IDX_NB,
  83. };
  84. enum mesh_proxy_idx_att
  85. {
  86. /* Mesh Proxy Service Primary Service Declaration */
  87. MESH_PROXY_SERV_DECL = 0x00,
  88. /* Mesh Proxy Data IN Characteristic */
  89. MESH_PROXY_DATA_IN_VALUE_CHAR,
  90. MESH_PROXY_DATA_IN_VALUE_VAL,
  91. /* Mesh Provisioning Data OUT Characteristic */
  92. MESH_PROXY_DATA_OUT_VALUE_CHAR,
  93. MESH_PROXY_DATA_OUT_VALUE_VAL,
  94. MESH_PROXY_DATA_OUT_VALUE_CCC,
  95. /* Max number of characteristics */
  96. MESH_PROXY_IDX_NB,
  97. };
  98. /* Define the available custom service states */
  99. enum mesh_serv_state
  100. {
  101. MESH_NO_SERVICES,
  102. MESH_PROV_SERVICE_DONE,
  103. MESH_PROXY_SERVICE_DONE,
  104. MESH_SERV_STATE_MAX
  105. };
  106. /* ----------------------------------------------------------------------------
  107. * Global variables and types
  108. * --------------------------------------------------------------------------*/
  109. typedef uint16 (* mesh_prov_data_in_wt_cb)
  110. (
  111. uint16 conn_hndl,
  112. uint16 offset,
  113. uint16 length,
  114. uint8 *value
  115. );
  116. typedef uint16 (* mesh_prov_data_out_ccd_cb)
  117. (
  118. uint16 conn_hndl,
  119. uint8 enabled
  120. );
  121. /**
  122. * Mesh Prov application callbacks
  123. */
  124. typedef struct
  125. {
  126. /** Provisioning Data IN Callback */
  127. mesh_prov_data_in_wt_cb prov_data_in_cb;
  128. /** Provisioning Data OUT notif Changed */
  129. mesh_prov_data_out_ccd_cb prov_data_out_ccd_cb;
  130. } mesh_prov_cb;
  131. typedef uint16 (* mesh_proxy_data_in_wt_cb)
  132. (
  133. uint16 conn_hndl,
  134. uint16 offset,
  135. uint16 length,
  136. uint8 *value
  137. );
  138. typedef uint16 (* mesh_proxy_data_out_ccd_cb)
  139. (
  140. uint16 conn_hndl,
  141. uint8 enabled
  142. );
  143. /**
  144. * Mesh Proxy application callbacks
  145. */
  146. typedef struct
  147. {
  148. /** Proxy Data IN Callback */
  149. mesh_proxy_data_in_wt_cb proxy_data_in_cb;
  150. /** Proxy Data OUT notif Changed */
  151. mesh_proxy_data_out_ccd_cb proxy_data_out_ccd_cb;
  152. } mesh_proxy_cb;
  153. /* ----------------------------------------------------------------------------
  154. * Function prototype definitions
  155. * --------------------------------------------------------------------------*/
  156. /**
  157. * Register Mesh Provisioning Service Instance
  158. *
  159. * \param [in] cb application callbacks
  160. */
  161. bStatus_t mesh_prov_init (mesh_prov_cb *cb);
  162. /**
  163. * Deregister Mesh Provisioning Service Instance
  164. *
  165. */
  166. bStatus_t mesh_prov_deinit(void);
  167. /**
  168. * Mesh Provisioning Data out Notifications
  169. *
  170. * Notification will only be sent if given client enabled notifications before.
  171. *
  172. * \param [in] conn_hndl Connection Identifier
  173. * \param [in] attidx Attribute Index
  174. * \param [in] val Pointer to Data to be sent
  175. * \param [in] val_len Length of Data to be sent
  176. */
  177. bStatus_t mesh_prov_notify_data_out
  178. (
  179. uint16 conn_hndl,
  180. uint8 attidx,
  181. uint8 * val,
  182. uint8 val_len
  183. );
  184. /**
  185. * Register Mesh Proxy Service Instance
  186. *
  187. * \param [in] cb application callbacks
  188. */
  189. bStatus_t mesh_proxy_init (mesh_proxy_cb *cb);
  190. /**
  191. * Deregister Mesh Proxy Service Instance
  192. *
  193. */
  194. bStatus_t mesh_proxy_deinit(void);
  195. /**
  196. * Mesh Proxy Data out Notifications
  197. *
  198. * Notification will only be sent if given client enabled notifications before.
  199. *
  200. * \param [in] conn_hndl Connection Identifier
  201. * \param [in] attidx Attribute Index
  202. * \param [in] val Pointer to Data to be sent
  203. * \param [in] val_len Length of Data to be sent
  204. */
  205. bStatus_t mesh_proxy_notify_data_out
  206. (
  207. uint16 conn_hndl,
  208. uint8 attidx,
  209. uint8 * val,
  210. uint8 val_len
  211. );
  212. /* ----------------------------------------------------------------------------
  213. * Close the 'extern "C"' block
  214. * ------------------------------------------------------------------------- */
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif /* _MESH_SERVICES_H */