ble_gattc_evt_conn.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**
  2. * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "ble_gattc_evt_conn.h"
  41. #include "ble_serialization.h"
  42. #include "ble_gattc_struct_serialization.h"
  43. #include "app_util.h"
  44. #include <string.h>
  45. uint32_t ble_gattc_evt_attr_info_disc_rsp_enc(ble_evt_t const * const p_event,
  46. uint32_t event_len,
  47. uint8_t * const p_buf,
  48. uint32_t * const p_buf_len)
  49. {
  50. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_ATTR_INFO_DISC_RSP);
  51. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  52. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  53. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  54. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.attr_info_disc_rsp,
  55. ble_gattc_evt_attr_info_disc_rsp_t_enc);
  56. SER_EVT_ENC_END;
  57. }
  58. uint32_t ble_gattc_evt_char_disc_rsp_enc(ble_evt_t const * const p_event,
  59. uint32_t event_len,
  60. uint8_t * const p_buf,
  61. uint32_t * const p_buf_len)
  62. {
  63. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_DISC_RSP);
  64. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  65. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  66. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  67. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_disc_rsp,
  68. ble_gattc_evt_char_disc_rsp_t_enc);
  69. SER_EVT_ENC_END;
  70. }
  71. uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_enc(ble_evt_t const * const p_event,
  72. uint32_t event_len,
  73. uint8_t * const p_buf,
  74. uint32_t * const p_buf_len)
  75. {
  76. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP);
  77. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  78. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  79. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  80. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_val_by_uuid_read_rsp,
  81. ble_gattc_evt_char_val_by_uuid_read_rsp_t_enc);
  82. SER_EVT_ENC_END;
  83. }
  84. uint32_t ble_gattc_evt_char_vals_read_rsp_enc(ble_evt_t const * const p_event,
  85. uint32_t event_len,
  86. uint8_t * const p_buf,
  87. uint32_t * const p_buf_len)
  88. {
  89. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VALS_READ_RSP);
  90. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  91. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  92. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  93. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_vals_read_rsp,
  94. ble_gattc_evt_char_vals_read_rsp_t_enc);
  95. SER_EVT_ENC_END;
  96. }
  97. uint32_t ble_gattc_evt_desc_disc_rsp_enc(ble_evt_t const * const p_event,
  98. uint32_t event_len,
  99. uint8_t * const p_buf,
  100. uint32_t * const p_buf_len)
  101. {
  102. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_DESC_DISC_RSP);
  103. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  104. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  105. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  106. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.desc_disc_rsp,
  107. ble_gattc_evt_desc_disc_rsp_t_enc);
  108. SER_EVT_ENC_END;
  109. }
  110. uint32_t ble_gattc_evt_hvx_enc(ble_evt_t const * const p_event,
  111. uint32_t event_len,
  112. uint8_t * const p_buf,
  113. uint32_t * const p_buf_len)
  114. {
  115. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_HVX);
  116. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  117. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  118. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  119. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.hvx, ble_gattc_evt_hvx_t_enc);
  120. SER_EVT_ENC_END;
  121. }
  122. uint32_t ble_gattc_evt_prim_srvc_disc_rsp_enc(ble_evt_t const * const p_event,
  123. uint32_t event_len,
  124. uint8_t * const p_buf,
  125. uint32_t * const p_buf_len)
  126. {
  127. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP);
  128. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  129. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  130. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  131. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.prim_srvc_disc_rsp,
  132. ble_gattc_evt_prim_srvc_disc_rsp_t_enc);
  133. SER_EVT_ENC_END;
  134. }
  135. uint32_t ble_gattc_evt_read_rsp_enc(ble_evt_t const * const p_event,
  136. uint32_t event_len,
  137. uint8_t * const p_buf,
  138. uint32_t * const p_buf_len)
  139. {
  140. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_READ_RSP);
  141. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  142. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  143. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  144. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.read_rsp,
  145. ble_gattc_evt_read_rsp_t_enc);
  146. SER_EVT_ENC_END;
  147. }
  148. uint32_t ble_gattc_evt_rel_disc_rsp_enc(ble_evt_t const * const p_event,
  149. uint32_t event_len,
  150. uint8_t * const p_buf,
  151. uint32_t * const p_buf_len)
  152. {
  153. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_REL_DISC_RSP);
  154. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  155. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  156. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  157. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.rel_disc_rsp,
  158. ble_gattc_evt_rel_disc_rsp_t_enc);
  159. SER_EVT_ENC_END;
  160. }
  161. uint32_t ble_gattc_evt_timeout_enc(ble_evt_t const * const p_event,
  162. uint32_t event_len,
  163. uint8_t * const p_buf,
  164. uint32_t * const p_buf_len)
  165. {
  166. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_TIMEOUT);
  167. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  168. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  169. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  170. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.timeout,
  171. ble_gattc_evt_timeout_t_enc);
  172. SER_EVT_ENC_END;
  173. }
  174. uint32_t ble_gattc_evt_write_rsp_enc(ble_evt_t const * const p_event,
  175. uint32_t event_len,
  176. uint8_t * const p_buf,
  177. uint32_t * const p_buf_len)
  178. {
  179. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_RSP);
  180. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  181. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  182. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  183. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.write_rsp,
  184. ble_gattc_evt_write_rsp_t_enc);
  185. SER_EVT_ENC_END;
  186. }
  187. uint32_t ble_gattc_evt_exchange_mtu_rsp_enc(ble_evt_t const * const p_event,
  188. uint32_t event_len,
  189. uint8_t * const p_buf,
  190. uint32_t * const p_buf_len)
  191. {
  192. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_EXCHANGE_MTU_RSP);
  193. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  194. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  195. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  196. SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp,
  197. ble_gattc_evt_exchange_mtu_rsp_t_enc);
  198. SER_EVT_ENC_END;
  199. }
  200. #if NRF_SD_BLE_API_VERSION >= 4
  201. uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event,
  202. uint32_t event_len,
  203. uint8_t * const p_buf,
  204. uint32_t * const p_buf_len)
  205. {
  206. SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE);
  207. SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
  208. SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
  209. SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
  210. SER_PUSH_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count);
  211. SER_EVT_ENC_END;
  212. }
  213. #endif