ble_app.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. #ifndef BLE_APP_H__
  41. #define BLE_APP_H__
  42. /**
  43. * @addtogroup ser_codecs Serialization codecs
  44. * @ingroup ble_sdk_lib_serialization
  45. */
  46. /**
  47. * @addtogroup ser_app_s130_codecs Application codecs for S132 and S140
  48. * @ingroup ser_codecs_app
  49. */
  50. /**@file
  51. *
  52. * @defgroup ble_app Application command request encoders and command response decoders
  53. * @{
  54. * @ingroup ser_app_s130_codecs
  55. *
  56. * @brief Application command request encoders and command response decoders.
  57. */
  58. #include "ble.h"
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  63. /**
  64. * @brief Encodes @ref sd_ble_tx_packet_count_get command request.
  65. *
  66. * @sa @ref ble_tx_packet_count_get_rsp_dec for command response decoder.
  67. *
  68. * @param[in] conn_handle Connection handle.
  69. * @param[in] p_count Pointer to count value to be filled.
  70. * @param[in] p_buf Pointer to buffer where encoded data command will be returned.
  71. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  72. * \c out: Length of the encoded command packet.
  73. *
  74. * @note \p p_count will not be updated by the command
  75. * request encoder. Updated values are set by @ref ble_tx_packet_count_get_rsp_dec.
  76. *
  77. * @retval NRF_SUCCESS Encoding success.
  78. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  79. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  80. */
  81. uint32_t ble_tx_packet_count_get_req_enc(uint16_t conn_handle,
  82. uint8_t const * const p_count,
  83. uint8_t * const p_buf,
  84. uint32_t * const p_buf_len);
  85. /**
  86. * @brief Decodes a response to @ref sd_ble_tx_packet_count_get command.
  87. *
  88. * @sa @ref ble_tx_packet_count_get_req_enc for command request encoder.
  89. *
  90. * @param[in] p_buf Pointer to the beginning of a command response packet.
  91. * @param[in] packet_len Length (in bytes) of the response packet.
  92. * @param[out] pp_count Pointer to the pointer to count value.
  93. * @param[out] p_result_code Command result code.
  94. *
  95. * @retval NRF_SUCCESS Decoding success.
  96. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  97. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  98. * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match
  99. * expected operation code.
  100. */
  101. uint32_t ble_tx_packet_count_get_rsp_dec(uint8_t const * const p_buf,
  102. uint32_t packet_len,
  103. uint8_t * * const pp_count,
  104. uint32_t * const p_result_code);
  105. #endif
  106. /**@brief Encodes the @ref sd_ble_uuid_encode command request.
  107. *
  108. * @sa @ref ble_uuid_encode_rsp_dec for command response decoder.
  109. *
  110. * @param[in] p_uuid Pointer to a @ref ble_uuid_t structure that will be encoded into bytes.
  111. * @param[in] p_uuid_le_len Size of \p p_uuid_le, if \p p_uuid_le is not NULL
  112. * @param[in] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes(2 or 16)
  113. * will be stored. Can be NULL to calculate the required size.
  114. * @param[in] p_buf Pointer to a buffer where the encoded data command will be returned.
  115. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  116. * \c out: Length of the encoded command packet.
  117. *
  118. * @note \p p_uuid_le_len and \p p_uuid_le will not be updated by the command
  119. * request encoder. Updated values are set by @ref ble_uuid_encode_rsp_dec.
  120. *
  121. * @retval NRF_SUCCESS Encoding success.
  122. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  123. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  124. */
  125. uint32_t ble_uuid_encode_req_enc(ble_uuid_t const * const p_uuid,
  126. uint8_t const * const p_uuid_le_len,
  127. uint8_t const * const p_uuid_le,
  128. uint8_t * const p_buf,
  129. uint32_t * const p_buf_len);
  130. /**@brief Decodes a response to the @ref sd_ble_uuid_encode command.
  131. *
  132. * @sa @ref ble_uuid_encode_req_enc for command request encoder.
  133. *
  134. * @param[in] p_buf Pointer to the beginning of a command response packet.
  135. * @param[in] packet_len Length (in bytes) of a response packet.
  136. * @param[in,out] p_uuid_le_len \c in: Size (in bytes) of \p p_uuid_le buffer.
  137. * \c out: Length of decoded contents of \p p_uuid_le.
  138. * @param[out] p_uuid_le Pointer to a buffer where the encoded UUID will be stored.
  139. * @param[out] p_result_code Command result code.
  140. *
  141. * @retval NRF_SUCCESS Decoding success.
  142. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  143. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  144. * @retval NRF_ERROR_DATA_SIZE Length of \p p_uuid_le is too small to hold the decoded
  145. * value from response.
  146. * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match the expected
  147. * operation code.
  148. */
  149. uint32_t ble_uuid_encode_rsp_dec(uint8_t const * const p_buf,
  150. uint32_t packet_len,
  151. uint8_t * const p_uuid_le_len,
  152. uint8_t * const p_uuid_le,
  153. uint32_t * const p_result_code);
  154. /**@brief Encodes @ref sd_ble_uuid_decode command request.
  155. *
  156. * @sa @ref ble_uuid_decode_rsp_dec for command response decoder.
  157. *
  158. * @param[in] uuid_le_len Size of \p p_uuid_le if \p p_uuid_le is not NULL.
  159. * @param[in] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes(2 or 16)
  160. * are stored.
  161. * @param[out] p_uuid Pointer to a @ref ble_uuid_t structure were the raw UUID will be decoded.
  162. * @param[in] p_buf Pointer to the buffer where encoded data command will be returned.
  163. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  164. * \c out: Length of the encoded command packet.
  165. *
  166. * @note \p p_uuid will not be updated by the command request encoder.
  167. * Updated values are set by @ref ble_uuid_decode_rsp_dec.
  168. *
  169. * @retval NRF_SUCCESS Encoding success.
  170. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  171. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  172. */
  173. uint32_t ble_uuid_decode_req_enc(uint8_t uuid_le_len,
  174. uint8_t const * const p_uuid_le,
  175. ble_uuid_t * const p_uuid,
  176. uint8_t * const p_buf,
  177. uint32_t * const p_buf_len);
  178. /**@brief Decodes a response to the @ref sd_ble_uuid_decode command.
  179. *
  180. * @sa @ref ble_uuid_decode_req_enc for command request encoder.
  181. *
  182. * @param[in] p_buf Pointer to the beginning of command response packet.
  183. * @param[in] packet_len Length (in bytes) of the response packet.
  184. * @param[out] p_uuid Pointer to a buffer where the decoded UUID will be stored.
  185. * @param[out] p_result_code Command result code.
  186. *
  187. * @retval NRF_SUCCESS Decoding success.
  188. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  189. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  190. * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match the expected
  191. * operation code.
  192. */
  193. uint32_t ble_uuid_decode_rsp_dec(uint8_t const * const p_buf,
  194. uint32_t packet_len,
  195. ble_uuid_t * * const p_uuid,
  196. uint32_t * const p_result_code);
  197. /**@brief Encodes the @ref sd_ble_uuid_vs_add command request.
  198. *
  199. * @sa @ref ble_uuid_vs_add_rsp_dec for command response decoder.
  200. *
  201. * @param[in] p_vs_uuid Pointer to a @ref ble_uuid128_t structure.
  202. * @param[in] p_uuid_type Pointer to uint8_t where UUID type will be returned.
  203. * @param[in] p_buf Pointer to buffer where the encoded data command will be returned.
  204. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  205. * \c out: Length of encoded command packet.
  206. *
  207. * @note \p p_uuid_type will not be updated by the command request encoder.
  208. * Updated values are set by @ref ble_uuid_vs_add_rsp_dec.
  209. *
  210. * @retval NRF_SUCCESS Encoding success.
  211. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  212. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  213. */
  214. uint32_t ble_uuid_vs_add_req_enc(ble_uuid128_t const * const p_vs_uuid,
  215. uint8_t * const p_uuid_type,
  216. uint8_t * const p_buf,
  217. uint32_t * const p_buf_len);
  218. /**@brief Decodes response to the @ref sd_ble_uuid_vs_add command.
  219. *
  220. * @sa @ref ble_uuid_vs_add_req_enc for command request encoder.
  221. *
  222. * @param[in] p_buf Pointer to the beginning of command response packet.
  223. * @param[in] packet_len Length (in bytes) of a response packet.
  224. * @param[out] pp_uuid_type Pointer to a pointer to uint8_t where the decoded UUID type will be stored.
  225. * @param[out] p_result_code Command result code.
  226. *
  227. * @retval NRF_SUCCESS Decoding success.
  228. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  229. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  230. * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
  231. * operation code.
  232. */
  233. uint32_t ble_uuid_vs_add_rsp_dec(uint8_t const * const p_buf,
  234. uint32_t packet_len,
  235. uint8_t * * const pp_uuid_type,
  236. uint32_t * const p_result_code);
  237. /**@brief Encodes the @ref sd_ble_version_get command request.
  238. *
  239. * @sa @ref ble_version_get_rsp_dec for command response decoder.
  240. *
  241. * @param[in] p_version Pointer to a @ref ble_version_t structure to be filled by the response.
  242. * @param[in] p_buf Pointer to a buffer where the encoded data command will be returned.
  243. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  244. * \c out: Length of encoded command packet.
  245. *
  246. * @retval NRF_SUCCESS Encoding success.
  247. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  248. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  249. */
  250. uint32_t ble_version_get_req_enc(ble_version_t const * const p_version,
  251. uint8_t * const p_buf,
  252. uint32_t * const p_buf_len);
  253. /**@brief Decodes response to the @ref sd_ble_version_get command.
  254. *
  255. * @sa @ref ble_version_get_req_enc for command request encoder.
  256. *
  257. * @param[in] p_buf Pointer to the beginning of a command response packet.
  258. * @param[in] packet_len Length (in bytes) of the response packet.
  259. * @param[out] p_version Pointer to a @ref ble_version_t where the decoded version will be stored.
  260. * @param[out] p_result_code Command result code.
  261. *
  262. * @retval NRF_SUCCESS Version information stored successfully.
  263. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  264. * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
  265. * hold the decoded event.
  266. */
  267. uint32_t ble_version_get_rsp_dec(uint8_t const * const p_buf,
  268. uint32_t packet_len,
  269. ble_version_t * p_version,
  270. uint32_t * const p_result_code);
  271. /**@brief Encodes the @ref sd_ble_opt_set command request.
  272. *
  273. * @sa @ref ble_opt_set_rsp_dec for command response decoder.
  274. *
  275. * @param[in] opt_id Identifies type of parameter in ble_opt_t union.
  276. * @param[in] p_opt Pointer to the ble_opt_t union.
  277. * @param[in] p_buf Pointer to a buffer where the encoded data command will be returned.
  278. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  279. * \c out: Length of the encoded command packet.
  280. *
  281. * @retval NRF_SUCCESS Encoding success.
  282. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  283. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  284. * @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
  285. */
  286. uint32_t ble_opt_set_req_enc(uint32_t const opt_id,
  287. ble_opt_t const * const p_opt,
  288. uint8_t * const p_buf,
  289. uint32_t * const p_buf_len);
  290. /**@brief Decodes response to the @ref sd_ble_opt_set command.
  291. *
  292. * @sa @ref ble_opt_set_req_enc for command request encoder.
  293. *
  294. * @param[in] p_buf Pointer to the beginning of a command response packet.
  295. * @param[in] packet_len Length (in bytes) of the response packet.
  296. * @param[out] p_result_code Command result code.
  297. *
  298. * @retval NRF_SUCCESS Version information stored successfully.
  299. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  300. */
  301. uint32_t ble_opt_set_rsp_dec(uint8_t const * const p_buf,
  302. uint32_t packet_len,
  303. uint32_t * const p_result_code);
  304. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  305. /**@brief Encodes the @ref sd_ble_enable command request.
  306. *
  307. * @sa @ref ble_enable_rsp_dec for command response decoder.
  308. *
  309. * @param[in] p_ble_enable_params Pointer to the @ref ble_enable_params_t structure.
  310. * @param[in] p_buf Pointer to the buffer where encoded data command will be returned.
  311. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  312. * \c out: Length of the encoded command packet.
  313. *
  314. * @retval NRF_SUCCESS Encoding success.
  315. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  316. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  317. */
  318. uint32_t ble_enable_req_enc(ble_enable_params_t * p_ble_enable_params,
  319. uint8_t * const p_buf,
  320. uint32_t * const p_buf_len);
  321. #else
  322. /**@brief Encodes the @ref sd_ble_enable command request.
  323. *
  324. * @sa @ref ble_enable_rsp_dec for command response decoder.
  325. *
  326. * @param[in] p_buf Pointer to the buffer where encoded data command will be returned.
  327. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  328. * \c out: Length of the encoded command packet.
  329. *
  330. * @retval NRF_SUCCESS Encoding success.
  331. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  332. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  333. */
  334. uint32_t ble_enable_req_enc(uint8_t * const p_buf,
  335. uint32_t * const p_buf_len);
  336. #endif
  337. /**@brief Decodes response to the @ref sd_ble_enable command.
  338. *
  339. * @sa @ref ble_enable_req_enc for command request encoder.
  340. *
  341. * @param[in] p_buf Pointer to the beginning of a command response packet.
  342. * @param[in] packet_len Length (in bytes) of the response packet.
  343. * @param[out] p_result_code Command result code.
  344. *
  345. * @retval NRF_SUCCESS Success.
  346. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  347. * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
  348. * hold the decoded event.
  349. */
  350. uint32_t ble_enable_rsp_dec(uint8_t const * const p_buf,
  351. uint32_t packet_len,
  352. uint32_t * const p_result_code);
  353. /**@brief Encodes the @ref sd_ble_opt_get command request.
  354. *
  355. * @sa @ref ble_opt_get_rsp_dec for command response decoder.
  356. *
  357. * @param[in] opt_id Identifies the type of parameter in the ble_opt_t union.
  358. * @param[in] p_opt Pointer to the @ref ble_opt_t union to be filled by the response.
  359. * @param[in] p_buf Pointer to the buffer where the encoded data command will be returned.
  360. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  361. * \c out: Length of the encoded command packet.
  362. *
  363. * @retval NRF_SUCCESS Encoding success.
  364. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  365. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  366. * @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
  367. */
  368. uint32_t ble_opt_get_req_enc(uint32_t opt_id,
  369. ble_opt_t const * const p_opt,
  370. uint8_t * const p_buf,
  371. uint32_t * const p_buf_len);
  372. /**@brief Decodes response to the @ref sd_ble_opt_get command.
  373. *
  374. * @sa @ref ble_opt_get_req_enc for command request encoder.
  375. *
  376. * @param[in] p_buf Pointer to the beginning of a command response packet.
  377. * @param[in] packet_len Length (in bytes) of the response packet.
  378. * @param[out] p_opt_id Pointer to the decoded opt_id.
  379. * @param[out] p_opt Pointer to the decoded @ref ble_opt_t union.
  380. * @param[out] p_result_code Command result code.
  381. *
  382. * @retval NRF_SUCCESS Opt stored successfully.
  383. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  384. * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
  385. * hold the decoded event.
  386. * @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
  387. */
  388. uint32_t ble_opt_get_rsp_dec(uint8_t const * const p_buf,
  389. uint32_t packet_len,
  390. uint32_t * const p_opt_id,
  391. ble_opt_t * const p_opt,
  392. uint32_t * const p_result_code);
  393. /**@brief Encodes the @ref sd_ble_user_mem_reply command request.
  394. *
  395. * @sa @ref ble_user_mem_reply_rsp_dec for command response decoder.
  396. *
  397. * @param[in] conn_handle Connection handle.
  398. * @param[in] p_block Pointer to the @ref ble_user_mem_block_t structure.
  399. * @param[in] p_buf Pointer to the buffer where the encoded data command will be returned.
  400. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  401. * \c out: Length of the encoded command packet.
  402. *
  403. * @retval NRF_SUCCESS Encoding success.
  404. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  405. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  406. * @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
  407. */
  408. uint32_t ble_user_mem_reply_req_enc(uint16_t conn_handle,
  409. ble_user_mem_block_t const * p_block,
  410. uint8_t * const p_buf,
  411. uint32_t * const p_buf_len);
  412. /**@brief Decodes response to the @ref sd_ble_user_mem_reply command.
  413. *
  414. * @sa @ref ble_user_mem_reply_req_enc for command request encoder.
  415. *
  416. * @param[in] p_buf Pointer to the beginning of a command response packet.
  417. * @param[in] packet_len Length (in bytes) of the response packet.
  418. * @param[out] p_result_code Command result code.
  419. *
  420. * @retval NRF_SUCCESS Opt stored successfully.
  421. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  422. * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
  423. * hold the decoded event.
  424. * @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
  425. */
  426. uint32_t ble_user_mem_reply_rsp_dec(uint8_t const * const p_buf,
  427. uint32_t packet_len,
  428. uint32_t * const p_result_code);
  429. #if NRF_SD_BLE_API_VERSION >= 4
  430. /**@brief Encodes the @ref sd_ble_cfg_set command request.
  431. *
  432. * @sa @ref ble_cfg_set_rsp_dec for command response decoder.
  433. *
  434. * @param[in] cfg_id Configuratio id.
  435. * @param[in] p_cfg Pointer to the configuration.
  436. * @param[in] p_buf Pointer to the buffer where the encoded data command will be returned.
  437. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  438. * \c out: Length of the encoded command packet.
  439. *
  440. * @retval NRF_SUCCESS Encoding success.
  441. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  442. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  443. * @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
  444. */
  445. uint32_t ble_cfg_set_req_enc(uint32_t cfg_id,
  446. ble_cfg_t const * p_cfg,
  447. uint8_t * const p_buf,
  448. uint32_t * const p_buf_len);
  449. /**@brief Decodes response to the @ref sd_ble_cfg_set command.
  450. *
  451. * @sa @ref ble_cfg_set_req_enc for command request encoder.
  452. *
  453. * @param[in] p_buf Pointer to the beginning of a command response packet.
  454. * @param[in] packet_len Length (in bytes) of the response packet.
  455. * @param[out] p_result_code Command result code.
  456. *
  457. * @retval NRF_SUCCESS Opt stored successfully.
  458. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  459. * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
  460. * hold the decoded event.
  461. * @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
  462. */
  463. uint32_t ble_cfg_set_rsp_dec(uint8_t const * const p_buf,
  464. uint32_t packet_len,
  465. uint32_t * const p_result_code);
  466. #endif //NRF_SD_BLE_API_VERSION >= 4
  467. /**@brief Event decoding dispatcher.
  468. *
  469. * The event decoding dispatcher will route the event packet to the correct decoder, which in turn
  470. * decodes the contents of the event and updates the \p p_event struct.
  471. *
  472. * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
  473. *
  474. * @param[in] p_buf Pointer to the beginning of the event packet.
  475. * @param[in] packet_len Length (in bytes) of the event packet.
  476. * @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be
  477. * stored. If NULL, the required length will be returned in \p p_event_len.
  478. * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
  479. * \c out: Length of the decoded contents of \p p_event.
  480. *
  481. * @retval NRF_SUCCESS Decoding success.
  482. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  483. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  484. * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
  485. * hold the decoded event.
  486. * @retval NRF_ERROR_NOT_FOUND Decoding failure. No event decoder is available.
  487. */
  488. uint32_t ble_event_dec(uint8_t const * const p_buf,
  489. uint32_t packet_len,
  490. ble_evt_t * const p_event,
  491. uint32_t * const p_event_len);
  492. /** @} */
  493. #ifdef __cplusplus
  494. }
  495. #endif
  496. #endif