ble_gattc_evt_app.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /**
  2. * Copyright (c) 2013 - 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_app.h"
  41. #include <string.h>
  42. #include "ble_serialization.h"
  43. #include "ble_gattc_struct_serialization.h"
  44. #include "app_util.h"
  45. uint32_t ble_gattc_evt_attr_info_disc_rsp_dec(uint8_t const * const p_buf,
  46. uint32_t packet_len,
  47. ble_evt_t * const p_event,
  48. uint32_t * const p_event_len)
  49. {
  50. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_ATTR_INFO_DISC_RSP, gattc, attr_info_disc_rsp);
  51. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  52. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  53. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  54. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.attr_info_disc_rsp,
  55. ble_gattc_evt_attr_info_disc_rsp_t_dec);
  56. SER_EVT_DEC_END;
  57. }
  58. uint32_t ble_gattc_evt_char_disc_rsp_dec(uint8_t const * const p_buf,
  59. uint32_t packet_len,
  60. ble_evt_t * const p_event,
  61. uint32_t * const p_event_len)
  62. {
  63. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_DISC_RSP, gattc, char_disc_rsp);
  64. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  65. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  66. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  67. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_disc_rsp,
  68. ble_gattc_evt_char_disc_rsp_t_dec);
  69. SER_EVT_DEC_END;
  70. }
  71. uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_dec(uint8_t const * const p_buf,
  72. uint32_t packet_len,
  73. ble_evt_t * const p_event,
  74. uint32_t * const p_event_len)
  75. {
  76. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP, gattc, char_val_by_uuid_read_rsp);
  77. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  78. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  79. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  80. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_val_by_uuid_read_rsp,
  81. ble_gattc_evt_char_val_by_uuid_read_rsp_t_dec);
  82. SER_EVT_DEC_END;
  83. }
  84. uint32_t ble_gattc_evt_char_vals_read_rsp_dec(uint8_t const * const p_buf,
  85. uint32_t packet_len,
  86. ble_evt_t * const p_event,
  87. uint32_t * const p_event_len)
  88. {
  89. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_VALS_READ_RSP, gattc, char_vals_read_rsp);
  90. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  91. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  92. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  93. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_vals_read_rsp,
  94. ble_gattc_evt_char_vals_read_rsp_t_dec);
  95. SER_EVT_DEC_END;
  96. }
  97. uint32_t ble_gattc_evt_desc_disc_rsp_dec(uint8_t const * const p_buf,
  98. uint32_t packet_len,
  99. ble_evt_t * const p_event,
  100. uint32_t * const p_event_len)
  101. {
  102. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_DESC_DISC_RSP, gattc, desc_disc_rsp);
  103. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  104. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  105. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  106. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.desc_disc_rsp,
  107. ble_gattc_evt_desc_disc_rsp_t_dec);
  108. SER_EVT_DEC_END;
  109. }
  110. uint32_t ble_gattc_evt_hvx_dec(uint8_t const * const p_buf,
  111. uint32_t packet_len,
  112. ble_evt_t * const p_event,
  113. uint32_t * const p_event_len)
  114. {
  115. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_HVX, gattc, hvx);
  116. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  117. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  118. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  119. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.hvx,
  120. ble_gattc_evt_hvx_t_dec);
  121. SER_EVT_DEC_END;
  122. }
  123. uint32_t ble_gattc_evt_prim_srvc_disc_rsp_dec(uint8_t const * const p_buf,
  124. uint32_t packet_len,
  125. ble_evt_t * const p_event,
  126. uint32_t * const p_event_len)
  127. {
  128. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, gattc, prim_srvc_disc_rsp);
  129. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  130. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  131. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  132. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.prim_srvc_disc_rsp,
  133. ble_gattc_evt_prim_srvc_disc_rsp_t_dec);
  134. SER_EVT_DEC_END;
  135. }
  136. uint32_t ble_gattc_evt_read_rsp_dec(uint8_t const * const p_buf,
  137. uint32_t packet_len,
  138. ble_evt_t * const p_event,
  139. uint32_t * const p_event_len)
  140. {
  141. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_READ_RSP, gattc, read_rsp);
  142. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  143. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  144. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  145. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.read_rsp,
  146. ble_gattc_evt_read_rsp_t_dec);
  147. SER_EVT_DEC_END;
  148. }
  149. #define BLE_GATTC_EVT_REL_DISC_RSP_COUNT_POSITION 6
  150. uint32_t ble_gattc_evt_rel_disc_rsp_dec(uint8_t const * const p_buf,
  151. uint32_t packet_len,
  152. ble_evt_t * const p_event,
  153. uint32_t * const p_event_len)
  154. {
  155. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_READ_RSP, gattc, rel_disc_rsp);
  156. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  157. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  158. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  159. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.rel_disc_rsp,
  160. ble_gattc_evt_rel_disc_rsp_t_dec);
  161. SER_EVT_DEC_END;
  162. }
  163. uint32_t ble_gattc_evt_timeout_dec(uint8_t const * const p_buf,
  164. uint32_t packet_len,
  165. ble_evt_t * const p_event,
  166. uint32_t * const p_event_len)
  167. {
  168. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_TIMEOUT, gattc, timeout);
  169. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  170. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  171. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  172. SER_PULL_FIELD(&p_event->evt.gattc_evt.params.timeout,
  173. ble_gattc_evt_timeout_t_dec);
  174. SER_EVT_DEC_END;
  175. }
  176. uint32_t ble_gattc_evt_write_rsp_dec(uint8_t const * const p_buf,
  177. uint32_t packet_len,
  178. ble_evt_t * const p_event,
  179. uint32_t * const p_event_len)
  180. {
  181. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_WRITE_RSP, gattc, write_rsp);
  182. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  183. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  184. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  185. SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.write_rsp,
  186. ble_gattc_evt_write_rsp_t_dec);
  187. SER_EVT_DEC_END;
  188. }
  189. uint32_t ble_gattc_evt_exchange_mtu_rsp_dec(uint8_t const * const p_buf,
  190. uint32_t packet_len,
  191. ble_evt_t * const p_event,
  192. uint32_t * const p_event_len)
  193. {
  194. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_EXCHANGE_MTU_RSP, gattc, exchange_mtu_rsp);
  195. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  196. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  197. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  198. SER_PULL_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp,
  199. ble_gattc_evt_exchange_mtu_rsp_t_dec);
  200. SER_EVT_DEC_END;
  201. }
  202. #if NRF_SD_BLE_API_VERSION >= 4
  203. uint32_t ble_gattc_evt_write_cmd_tx_complete_dec(uint8_t const * const p_buf,
  204. uint32_t packet_len,
  205. ble_evt_t * const p_event,
  206. uint32_t * const p_event_len)
  207. {
  208. SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE, gattc, write_cmd_tx_complete);
  209. SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
  210. SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
  211. SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
  212. SER_PULL_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count);
  213. SER_EVT_DEC_END;
  214. }
  215. #endif