mesh_clients.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /**
  2. * \file mesh_clients.h
  3. *
  4. *
  5. */
  6. /*
  7. * Copyright (C) 2018. Mindtree Limited.
  8. * All rights reserved.
  9. */
  10. #ifndef _MESH_CLIENTS_H
  11. #define _MESH_CLIENTS_H
  12. /* --------------------------------------------- Header File Inclusion */
  13. #include "EM_os.h"
  14. #include "blebrr.h"
  15. #include "gatt.h"
  16. #include "gatt_uuid.h"
  17. #include "bleMesh.h"
  18. /* --------------------------------------------- Global Definitions */
  19. /* Mesh GATT Bearer Related Service Assigned Numbers as arrays */
  20. #define MESH_PROV_SERVICE_UUID16 { 0x27, 0x18}
  21. #define MESH_PROV_DATA_IN_UUID16 { 0xDB, 0x2A}
  22. #define MESH_PROV_DATA_OUT_UUID16 { 0xDC, 0x2A}
  23. #define MESH_PROXY_SERVICE_UUID16 { 0x28, 0x18}
  24. #define MESH_PROXY_DATA_IN_UUID16 { 0xDD, 0x2A}
  25. #define MESH_PROXY_DATA_OUT_UUID16 { 0xDE, 0x2A}
  26. /* Mesh GATT Bearer Related Service Assigned Numbers */
  27. /* Use the UUID from Mesh Asigned numbers headers */
  28. #define UUID_MESH_PROVISIONING_SERVICE (0x1827)
  29. #define UUID_MESH_PROVISIONING_DATA_IN (0x2ADB)
  30. #define UUID_MESH_PROVISIONING_DATA_OUT (0x2ADC)
  31. /* Use the UUID from Mesh Asigned numbers headers */
  32. #define UUID_MESH_PROXY_SERVICE (0x1828)
  33. #define UUID_MESH_PROXY_DATA_IN (0x2ADD)
  34. #define UUID_MESH_PROXY_DATA_OUT (0x2ADE)
  35. /* --------------------------------------------- Structures/Data Types */
  36. /**
  37. * \brief Mesh Provisioning Data Out notification callback
  38. *
  39. * Called when Client received Mesh Provisioning data out
  40. * notification from server.
  41. *
  42. * \param [in] client client instance
  43. * \param [in] length length of data
  44. * \param [in] value mesh prov data out value from Server
  45. *
  46. */
  47. typedef void (* mesh_prov_client_data_out_cb)
  48. (
  49. uint16_t conidx,
  50. uint16_t length,
  51. uint8_t * value
  52. );
  53. /**
  54. * \brief Set Notifications Enable Disable Callback
  55. *
  56. * \param [in] conidx connection index
  57. * \param [in] flag Enable/Disable State Flag
  58. * \param [in] status operation status
  59. *
  60. */
  61. typedef void (* mesh_prov_client_data_out_ntf_status_cb)
  62. (
  63. uint16_t conidx,
  64. uint8_t flag,
  65. uint8_t status
  66. );
  67. /**
  68. * \brief MEsh Provisioning Cliet application callbacks
  69. *
  70. */
  71. typedef struct
  72. {
  73. /** Mesh Procv Client Data Out callback */
  74. mesh_prov_client_data_out_cb mesh_prov_data_out_notif;
  75. /**
  76. * Called once client enabled/disabled event
  77. * characteristic notifications/indications
  78. */
  79. mesh_prov_client_data_out_ntf_status_cb mesh_prov_ntf_status;
  80. } mesh_prov_client_cb;
  81. /**
  82. * \brief Mesh Provisioning Data Out notification callback
  83. *
  84. * Called when Client received Mesh Provisioning data out
  85. * notification from server.
  86. *
  87. * \param [in] client client instance
  88. * \param [in] length length of data
  89. * \param [in] value mesh prov data out value from Server
  90. *
  91. */
  92. typedef void (* mesh_proxy_client_data_out_cb)
  93. (
  94. uint16_t conidx,
  95. uint16_t length,
  96. uint8_t * value
  97. );
  98. /**
  99. * \brief Set Notifications Enable Disable Callback
  100. *
  101. * \param [in] conidx connection index
  102. * \param [in] flag Enable/Disable State Flag
  103. * \param [in] status operation status
  104. *
  105. */
  106. typedef void (* mesh_proxy_client_data_out_ntf_status_cb)
  107. (
  108. uint16_t conidx,
  109. uint8_t flag,
  110. uint8_t status
  111. );
  112. /**
  113. * \brief Mesh Provisioning Cliet application callbacks
  114. *
  115. */
  116. typedef struct
  117. {
  118. /** Mesh Procv Client Data Out callback */
  119. mesh_proxy_client_data_out_cb mesh_proxy_data_out_notif;
  120. /**
  121. * Called once client enabled/disabled event
  122. * characteristic notifications/indications
  123. */
  124. mesh_proxy_client_data_out_ntf_status_cb mesh_proxy_ntf_status;
  125. } mesh_proxy_client_cb;
  126. struct mesh_cli_env_tag
  127. {
  128. /* Connection index */
  129. uint16_t conidx;
  130. /* Provisioning Service Related Handles */
  131. uint16_t prov_start_hdl;
  132. uint16_t prov_end_hdl;
  133. uint16_t prov_data_in_hdl;
  134. uint16_t prov_data_out_hdl;
  135. uint16_t prov_data_out_cccd_hdl;
  136. /* Proxy Service Related Handles */
  137. uint16_t proxy_start_hdl;
  138. uint16_t proxy_end_hdl;
  139. uint16_t proxy_data_in_hdl;
  140. uint16_t proxy_data_out_hdl;
  141. uint16_t proxy_data_out_cccd_hdl;
  142. /* Current Notification Mode and State */
  143. uint16_t curr_notif_state;
  144. uint8_t curr_notif_mode;
  145. };
  146. extern struct mesh_cli_env_tag mesh_cli_env[];
  147. /* --------------------------------------------- Macros */
  148. #define mesh_prov_client_discover_serv(cidx) \
  149. mesh_client_discover_services((BLEBRR_GATT_PROV_MODE), (cidx));
  150. #define mesh_proxy_client_discover_serv(cidx) \
  151. mesh_client_discover_services((BLEBRR_GATT_PROXY_MODE), (cidx));
  152. #define mesh_prov_client_data_in_write(cidx, val, len) \
  153. mesh_client_send_wwr((cidx), (val), (len), BLEBRR_GATT_PROV_MODE);
  154. #define mesh_proxy_client_data_in_write(cidx, val, len) \
  155. mesh_client_send_wwr((cidx), (val), (len), BLEBRR_GATT_PROXY_MODE);
  156. #define mesh_prov_client_enable_data_out(cidx) \
  157. mesh_client_config_ntf((cidx), BLEBRR_GATT_PROV_MODE, (true));
  158. #define mesh_proxy_client_enable_data_out(cidx) \
  159. mesh_client_config_ntf((cidx), BLEBRR_GATT_PROXY_MODE, (true));
  160. #define mesh_prov_client_disable_data_out(cidx) \
  161. mesh_client_config_ntf((cidx), BLEBRR_GATT_PROV_MODE, (false));
  162. #define mesh_proxy_client_disable_data_out(cidx) \
  163. mesh_client_config_ntf((cidx), BLEBRR_GATT_PROXY_MODE, (false));
  164. /* --------------------------------------------- Internal Functions */
  165. void mesh_client_process_gattMsg
  166. (
  167. gattMsgEvent_t *pMsg,
  168. uint8_t t_id
  169. );
  170. /* --------------------------------------------- API Declarations */
  171. /**
  172. * \brief Register Mesh Provisioning Client instance
  173. *
  174. * Function registers new Mesh Provisioning Client instance.
  175. *
  176. * \param [in] cb client application callbacks
  177. *
  178. * \return None
  179. *
  180. */
  181. void mesh_prov_client_init
  182. (
  183. mesh_prov_client_cb *cb
  184. );
  185. /**
  186. * \brief Register Mesh Proxy Client instance
  187. *
  188. * Function registers new Mesh Proxy Client instance.
  189. *
  190. * \param [in] cb client application callbacks
  191. *
  192. * \return None
  193. *
  194. */
  195. void mesh_proxy_client_init
  196. (
  197. mesh_proxy_client_cb *cb
  198. );
  199. void mesh_client_send_wwr
  200. (
  201. uint16_t conidx,
  202. uint8_t * value,
  203. uint16_t length,
  204. uint8_t serv_pref
  205. );
  206. API_RESULT mesh_client_config_ntf
  207. (
  208. uint16_t conidx,
  209. uint8_t serv_pref,
  210. uint8_t flag
  211. );
  212. void mesh_client_init(void);
  213. API_RESULT mesh_client_discover_services(uint16_t conidx, uint8_t serv_mode);
  214. void mesh_client_update_conidx (uint16_t conidx);
  215. #endif /* _MESH_CLIENTS_H */