ble_gattc_app.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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_app.h"
  41. #include <string.h>
  42. #include "ble_serialization.h"
  43. #include "ble_gattc_struct_serialization.h"
  44. #include "cond_field_serialization.h"
  45. #include "app_util.h"
  46. #include "ble_struct_serialization.h"
  47. #include "ble_types.h"
  48. uint32_t ble_gattc_attr_info_discover_req_enc(uint16_t conn_handle,
  49. ble_gattc_handle_range_t const * const p_handle_range,
  50. uint8_t * const p_buf,
  51. uint32_t * p_buf_len)
  52. {
  53. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
  54. SER_PUSH_uint16(&conn_handle);
  55. SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
  56. SER_REQ_ENC_END;
  57. }
  58. uint32_t ble_gattc_attr_info_discover_rsp_dec(uint8_t const * const p_buf,
  59. uint32_t packet_len,
  60. uint32_t * const p_result_code)
  61. {
  62. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
  63. }
  64. uint32_t ble_gattc_char_value_by_uuid_read_req_enc(uint16_t conn_handle,
  65. ble_uuid_t const * const p_uuid,
  66. ble_gattc_handle_range_t const * const p_handle_range,
  67. uint8_t * const p_buf,
  68. uint32_t * const p_buf_len)
  69. {
  70. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
  71. SER_PUSH_uint16(&conn_handle);
  72. SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
  73. SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
  74. SER_REQ_ENC_END;
  75. }
  76. uint32_t ble_gattc_char_value_by_uuid_read_rsp_dec(uint8_t const * const p_buf,
  77. uint32_t packet_len,
  78. uint32_t * const p_result_code)
  79. {
  80. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
  81. }
  82. uint32_t ble_gattc_char_values_read_req_enc(uint16_t conn_handle,
  83. uint16_t const * const p_handles,
  84. uint16_t handle_count,
  85. uint8_t * const p_buf,
  86. uint32_t * p_buf_len)
  87. {
  88. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHAR_VALUES_READ);
  89. SER_PUSH_uint16(&conn_handle);
  90. SER_PUSH_len16data16(p_handles, handle_count);
  91. SER_REQ_ENC_END;
  92. }
  93. uint32_t ble_gattc_char_values_read_rsp_dec(uint8_t const * const p_buf,
  94. uint32_t packet_len,
  95. uint32_t * const p_result_code)
  96. {
  97. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUES_READ);
  98. }
  99. uint32_t ble_gattc_characteristics_discover_req_enc(
  100. uint16_t conn_handle,
  101. ble_gattc_handle_range_t const * const p_handle_range,
  102. uint8_t * const p_buf,
  103. uint32_t * p_buf_len)
  104. {
  105. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
  106. SER_PUSH_uint16(&conn_handle);
  107. SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
  108. SER_REQ_ENC_END;
  109. }
  110. uint32_t ble_gattc_characteristics_discover_rsp_dec(uint8_t const * const p_buf,
  111. uint32_t packet_len,
  112. uint32_t * const p_result_code)
  113. {
  114. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
  115. }
  116. uint32_t ble_gattc_descriptors_discover_req_enc(
  117. uint16_t conn_handle,
  118. ble_gattc_handle_range_t const * const p_handle_range,
  119. uint8_t * const p_buf,
  120. uint32_t * p_buf_len)
  121. {
  122. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
  123. SER_PUSH_uint16(&conn_handle);
  124. SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
  125. SER_REQ_ENC_END;
  126. }
  127. uint32_t ble_gattc_descriptors_discover_rsp_dec(uint8_t const * const p_buf,
  128. uint32_t packet_len,
  129. uint32_t * const p_result_code)
  130. {
  131. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
  132. }
  133. uint32_t ble_gattc_hv_confirm_req_enc(uint16_t conn_handle,
  134. uint16_t handle,
  135. uint8_t * const p_buf,
  136. uint32_t * const p_buf_len)
  137. {
  138. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_HV_CONFIRM);
  139. SER_PUSH_uint16(&conn_handle);
  140. SER_PUSH_uint16(&handle);
  141. SER_REQ_ENC_END;
  142. }
  143. uint32_t ble_gattc_hv_confirm_rsp_dec(uint8_t const * const p_buf,
  144. uint32_t packet_len,
  145. uint32_t * const p_result_code)
  146. {
  147. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_HV_CONFIRM);
  148. }
  149. uint32_t ble_gattc_primary_services_discover_req_enc(uint16_t conn_handle,
  150. uint16_t start_handle,
  151. ble_uuid_t const * const p_srvc_uuid,
  152. uint8_t * const p_buf,
  153. uint32_t * p_buf_len)
  154. {
  155. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
  156. SER_PUSH_uint16(&conn_handle);
  157. SER_PUSH_uint16(&start_handle);
  158. SER_PUSH_COND(p_srvc_uuid, ble_uuid_t_enc);
  159. SER_REQ_ENC_END;
  160. }
  161. uint32_t ble_gattc_primary_services_discover_rsp_dec(uint8_t const * const p_buf,
  162. uint32_t packet_len,
  163. uint32_t * const p_result_code)
  164. {
  165. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
  166. }
  167. uint32_t ble_gattc_read_req_enc(uint16_t conn_handle,
  168. uint16_t handle,
  169. uint16_t offset,
  170. uint8_t * const p_buf,
  171. uint32_t * p_buf_len)
  172. {
  173. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_READ);
  174. SER_PUSH_uint16(&conn_handle);
  175. SER_PUSH_uint16(&handle);
  176. SER_PUSH_uint16(&offset);
  177. SER_REQ_ENC_END;
  178. }
  179. uint32_t ble_gattc_read_rsp_dec(uint8_t const * const p_buf,
  180. uint32_t packet_len,
  181. uint32_t * const p_result_code)
  182. {
  183. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_READ);
  184. }
  185. uint32_t ble_gattc_relationships_discover_req_enc(
  186. uint16_t conn_handle,
  187. ble_gattc_handle_range_t const * const p_handle_range,
  188. uint8_t * const p_buf,
  189. uint32_t * p_buf_len)
  190. {
  191. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
  192. SER_PUSH_uint16(&conn_handle);
  193. SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
  194. SER_REQ_ENC_END;
  195. }
  196. uint32_t ble_gattc_relationships_discover_rsp_dec(uint8_t const * const p_buf,
  197. uint32_t packet_len,
  198. uint32_t * const p_result_code)
  199. {
  200. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
  201. }
  202. uint32_t ble_gattc_write_req_enc(uint16_t conn_handle,
  203. ble_gattc_write_params_t const * const p_write_params,
  204. uint8_t * const p_buf,
  205. uint32_t * p_buf_len)
  206. {
  207. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_WRITE);
  208. SER_PUSH_uint16(&conn_handle);
  209. SER_PUSH_COND(p_write_params, ble_gattc_write_params_t_enc);
  210. SER_REQ_ENC_END;
  211. }
  212. uint32_t ble_gattc_write_rsp_dec(uint8_t const * const p_buf,
  213. uint32_t packet_len,
  214. uint32_t * const p_result_code)
  215. {
  216. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_WRITE);
  217. }
  218. uint32_t ble_gattc_exchange_mtu_request_req_enc(uint16_t conn_handle,
  219. uint16_t client_rx_mtu,
  220. uint8_t * const p_buf,
  221. uint32_t * const p_buf_len)
  222. {
  223. SER_REQ_ENC_BEGIN(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
  224. SER_PUSH_uint16(&conn_handle);
  225. SER_PUSH_uint16(&client_rx_mtu);
  226. SER_REQ_ENC_END;
  227. }
  228. uint32_t ble_gattc_exchange_mtu_request_rsp_dec(uint8_t const * const p_buf,
  229. uint32_t packet_len,
  230. uint32_t * const p_result_code)
  231. {
  232. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
  233. }