ble_gattc_conn.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /**
  2. * Copyright (c) 2014 - 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_conn.h"
  41. #include "ble_serialization.h"
  42. #include "ble_struct_serialization.h"
  43. #include "ble_gattc_struct_serialization.h"
  44. #include "cond_field_serialization.h"
  45. #include "app_util.h"
  46. #include <string.h>
  47. uint32_t ble_gattc_attr_info_discover_req_dec(uint8_t const * const p_buf,
  48. uint16_t packet_len,
  49. uint16_t * const p_conn_handle,
  50. ble_gattc_handle_range_t * * const pp_handle_range)
  51. {
  52. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
  53. SER_ASSERT_NOT_NULL(p_conn_handle);
  54. SER_ASSERT_NOT_NULL(pp_handle_range);
  55. SER_ASSERT_NOT_NULL(*pp_handle_range);
  56. SER_PULL_uint16(p_conn_handle);
  57. SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
  58. SER_REQ_DEC_END;
  59. }
  60. uint32_t ble_gattc_attr_info_discover_rsp_enc(uint32_t return_code,
  61. uint8_t * const p_buf,
  62. uint32_t * const p_buf_len)
  63. {
  64. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
  65. }
  66. uint32_t ble_gattc_char_value_by_uuid_read_req_dec(uint8_t const * const p_buf,
  67. uint16_t packet_len,
  68. uint16_t * const p_conn_handle,
  69. ble_uuid_t * * const pp_uuid,
  70. ble_gattc_handle_range_t * * const
  71. pp_handle_range)
  72. {
  73. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
  74. SER_ASSERT_NOT_NULL(p_conn_handle);
  75. SER_ASSERT_NOT_NULL(pp_uuid);
  76. SER_ASSERT_NOT_NULL(*pp_uuid);
  77. SER_ASSERT_NOT_NULL(pp_handle_range);
  78. SER_ASSERT_NOT_NULL(*pp_handle_range);
  79. SER_PULL_uint16(p_conn_handle);
  80. SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
  81. SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
  82. SER_REQ_DEC_END;
  83. }
  84. uint32_t ble_gattc_char_value_by_uuid_read_rsp_enc(uint32_t return_code,
  85. uint8_t * const p_buf,
  86. uint32_t * const p_buf_len)
  87. {
  88. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
  89. }
  90. uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf,
  91. uint16_t packet_len,
  92. uint16_t * const p_conn_handle,
  93. uint16_t * * const pp_handles,
  94. uint16_t * const p_handle_count)
  95. {
  96. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUES_READ);
  97. SER_ASSERT_NOT_NULL(p_conn_handle);
  98. SER_ASSERT_NOT_NULL(pp_handles);
  99. SER_ASSERT_NOT_NULL(*pp_handles);
  100. SER_ASSERT_NOT_NULL(p_handle_count);
  101. SER_PULL_uint16(p_conn_handle);
  102. SER_PULL_len16data16(pp_handles, p_handle_count);
  103. SER_REQ_DEC_END;
  104. }
  105. uint32_t ble_gattc_char_values_read_rsp_enc(uint32_t return_code,
  106. uint8_t * const p_buf,
  107. uint32_t * const p_buf_len)
  108. {
  109. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUES_READ);
  110. }
  111. uint32_t ble_gattc_characteristics_discover_req_dec(
  112. uint8_t const * const p_buf,
  113. uint16_t packet_len,
  114. uint16_t * const p_conn_handle,
  115. ble_gattc_handle_range_t * * const pp_handle_range)
  116. {
  117. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
  118. SER_PULL_uint16(p_conn_handle);
  119. SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
  120. SER_REQ_DEC_END;
  121. }
  122. uint32_t ble_gattc_characteristics_discover_rsp_enc(uint32_t return_code,
  123. uint8_t * const p_buf,
  124. uint32_t * const p_buf_len)
  125. {
  126. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
  127. }
  128. uint32_t ble_gattc_descriptors_discover_req_dec(uint8_t const * const p_buf,
  129. uint16_t packet_len,
  130. uint16_t * const p_conn_handle,
  131. ble_gattc_handle_range_t * * const pp_handle_range)
  132. {
  133. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
  134. SER_PULL_uint16(p_conn_handle);
  135. SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
  136. SER_REQ_DEC_END;
  137. }
  138. uint32_t ble_gattc_descriptors_discover_rsp_enc(uint32_t return_code,
  139. uint8_t * const p_buf,
  140. uint32_t * const p_buf_len)
  141. {
  142. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
  143. }
  144. uint32_t ble_gattc_hv_confirm_req_dec(uint8_t const * const p_buf,
  145. uint32_t packet_len,
  146. uint16_t * const p_conn_handle,
  147. uint16_t * const p_handle)
  148. {
  149. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_HV_CONFIRM);
  150. SER_PULL_uint16(p_conn_handle);
  151. SER_PULL_uint16(p_handle);
  152. SER_REQ_DEC_END;
  153. }
  154. uint32_t ble_gattc_hv_confirm_rsp_enc(uint32_t return_code,
  155. uint8_t * const p_buf,
  156. uint32_t * const p_buf_len)
  157. {
  158. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_HV_CONFIRM);
  159. }
  160. uint32_t ble_gattc_primary_services_discover_req_dec(uint8_t const * const p_buf,
  161. uint16_t packet_len,
  162. uint16_t * const p_conn_handle,
  163. uint16_t * const p_start_handle,
  164. ble_uuid_t * * const pp_srvc_uuid)
  165. {
  166. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
  167. SER_PULL_uint16(p_conn_handle);
  168. SER_PULL_uint16(p_start_handle);
  169. SER_PULL_COND(pp_srvc_uuid, ble_uuid_t_dec);
  170. SER_REQ_DEC_END;
  171. }
  172. uint32_t ble_gattc_primary_services_discover_rsp_enc(uint32_t return_code,
  173. uint8_t * const p_buf,
  174. uint32_t * const p_buf_len)
  175. {
  176. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
  177. }
  178. uint32_t ble_gattc_read_req_dec(uint8_t const * const p_buf,
  179. uint16_t packet_len,
  180. uint16_t * const p_conn_handle,
  181. uint16_t * const p_handle,
  182. uint16_t * const p_offset)
  183. {
  184. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_READ);
  185. SER_PULL_uint16(p_conn_handle);
  186. SER_PULL_uint16(p_handle);
  187. SER_PULL_uint16(p_offset);
  188. SER_REQ_DEC_END;
  189. }
  190. uint32_t ble_gattc_read_rsp_enc(uint32_t return_code,
  191. uint8_t * const p_buf,
  192. uint32_t * const p_buf_len)
  193. {
  194. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_READ);
  195. }
  196. uint32_t ble_gattc_relationships_discover_req_dec(uint8_t const * const p_buf,
  197. uint16_t packet_len,
  198. uint16_t * const p_conn_handle,
  199. ble_gattc_handle_range_t * * const pp_handle_range)
  200. {
  201. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
  202. SER_PULL_uint16(p_conn_handle);
  203. SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
  204. SER_REQ_DEC_END;
  205. }
  206. uint32_t ble_gattc_relationships_discover_rsp_enc(uint32_t return_code,
  207. uint8_t * const p_buf,
  208. uint32_t * const p_buf_len)
  209. {
  210. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
  211. }
  212. uint32_t ble_gattc_write_req_dec(uint8_t const * const p_buf,
  213. uint16_t packet_len,
  214. uint16_t * const p_conn_handle,
  215. ble_gattc_write_params_t * * const pp_write_params)
  216. {
  217. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_WRITE);
  218. SER_PULL_uint16(p_conn_handle);
  219. SER_PULL_COND(pp_write_params, ble_gattc_write_params_t_dec);
  220. SER_REQ_DEC_END;
  221. }
  222. uint32_t ble_gattc_write_rsp_enc(uint32_t return_code,
  223. uint8_t * const p_buf,
  224. uint32_t * const p_buf_len)
  225. {
  226. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_WRITE);
  227. }
  228. uint32_t ble_gattc_exchange_mtu_request_req_dec(uint8_t const * const p_buf,
  229. uint16_t packet_len,
  230. uint16_t * const p_conn_handle,
  231. uint16_t * const p_client_rx_mtu)
  232. {
  233. SER_REQ_DEC_BEGIN(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
  234. SER_PULL_uint16(p_conn_handle);
  235. SER_PULL_uint16(p_client_rx_mtu);
  236. SER_REQ_DEC_END;
  237. }
  238. uint32_t ble_gattc_exchange_mtu_request_rsp_enc(uint32_t return_code,
  239. uint8_t * const p_buf,
  240. uint32_t * const p_buf_len)
  241. {
  242. SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
  243. }