app_mw_ble.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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.h"
  41. #include "ble_serialization.h"
  42. #include <stdint.h>
  43. #include "ble_app.h"
  44. #include "ser_sd_transport.h"
  45. #include "app_error.h"
  46. #include "app_ble_user_mem.h"
  47. #include "app_ble_gap_sec_keys.h"
  48. extern ser_ble_user_mem_t m_app_user_mem_table[];
  49. /**@brief Structure containing @ref sd_ble_uuid_encode output parameters. */
  50. typedef struct
  51. {
  52. uint8_t * p_uuid_le_len; /**< @ref sd_ble_uuid_encode appearance p_uuid_le_len output parameter. */
  53. uint8_t * p_uuid_le; /**< @ref sd_ble_uuid_encode appearance p_uuid_le output parameter. */
  54. } ble_uuid_encode_out_params_t;
  55. /**@brief Structure containing @ref sd_ble_user_mem_reply output parameters. */
  56. typedef struct
  57. {
  58. uint16_t conn_handle; /**< @ref sd_ble_user_mem_reply conn_handle. */
  59. uint8_t context_allocated; /**< @ref sd_ble_user_mem_reply user memory context allocated flag. */
  60. } ble_user_mem_reply_out_params_t;
  61. /**@brief Union containing BLE command output parameters. */
  62. typedef union
  63. {
  64. ble_uuid_encode_out_params_t ble_uuid_encode_out_params; /**< @ref sd_ble_uuid_encode output parameters. */
  65. ble_user_mem_reply_out_params_t ble_user_mem_reply_out_params; /**< @ref sd_ble_user_mem_reply output parameters. */
  66. } ble_command_output_params_t;
  67. static ble_command_output_params_t m_output_params; /**< BLE command output parameters. */
  68. static void * mp_out_params[3];
  69. static uint32_t m_uint32_param;
  70. static void tx_buf_alloc(uint8_t * * p_data, uint32_t * p_len)
  71. {
  72. uint32_t err_code;
  73. uint16_t len16;
  74. do
  75. {
  76. err_code = ser_sd_transport_tx_alloc(p_data, &len16);
  77. }
  78. while (err_code != NRF_SUCCESS);
  79. *p_data[0] = SER_PKT_TYPE_CMD;
  80. *p_len = (uint32_t)len16 - 1;
  81. }
  82. /**@brief Command response callback function for @ref sd_ble_uuid_encode BLE command.
  83. *
  84. * Callback for decoding the output parameters and the command response return code.
  85. *
  86. * @param[in] p_buffer Pointer to begin of command response buffer.
  87. * @param[in] length Length of data in bytes.
  88. *
  89. * @return Decoded command response return code.
  90. */
  91. static uint32_t uuid_encode_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  92. {
  93. uint32_t result_code;
  94. const uint32_t err_code =
  95. ble_uuid_encode_rsp_dec(p_buffer,
  96. length,
  97. m_output_params.ble_uuid_encode_out_params.p_uuid_le_len,
  98. m_output_params.ble_uuid_encode_out_params.p_uuid_le,
  99. &result_code);
  100. //@note: Should never fail.
  101. APP_ERROR_CHECK(err_code);
  102. return result_code;
  103. }
  104. #ifndef _sd_ble_uuid_encode
  105. #define _sd_ble_uuid_encode sd_ble_uuid_encode
  106. #endif
  107. uint32_t _sd_ble_uuid_encode(ble_uuid_t const * const p_uuid,
  108. uint8_t * const p_uuid_le_len,
  109. uint8_t * const p_uuid_le)
  110. {
  111. uint8_t * p_buffer;
  112. uint32_t buffer_length;
  113. tx_buf_alloc(&p_buffer, &buffer_length);
  114. m_output_params.ble_uuid_encode_out_params.p_uuid_le_len = p_uuid_le_len;
  115. m_output_params.ble_uuid_encode_out_params.p_uuid_le = p_uuid_le;
  116. uint32_t err_code = ble_uuid_encode_req_enc(p_uuid,
  117. p_uuid_le_len,
  118. p_uuid_le,
  119. &(p_buffer[1]),
  120. &buffer_length);
  121. //@note: Should never fail.
  122. APP_ERROR_CHECK(err_code);
  123. //@note: Increment buffer length as internally managed packet type field must be included.
  124. return ser_sd_transport_cmd_write(p_buffer,
  125. (++buffer_length),
  126. uuid_encode_rsp_dec);
  127. }
  128. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  129. /**@brief Command response callback function for @ref sd_ble_tx_packet_count_get BLE command.
  130. *
  131. * Callback for decoding the output parameters and the command response return code.
  132. *
  133. * @param[in] p_buffer Pointer to begin of command response buffer.
  134. * @param[in] length Length of data in bytes.
  135. *
  136. * @return Decoded command response return code.
  137. */
  138. static uint32_t tx_packet_count_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  139. {
  140. uint32_t result_code;
  141. const uint32_t err_code = ble_tx_packet_count_get_rsp_dec(p_buffer,
  142. length,
  143. (uint8_t * *)&mp_out_params[0],
  144. &result_code);
  145. //@note: Should never fail.
  146. APP_ERROR_CHECK(err_code);
  147. return result_code;
  148. }
  149. #ifndef _sd_ble_tx_packet_count_get
  150. #define _sd_ble_tx_packet_count_get sd_ble_tx_packet_count_get
  151. #endif
  152. uint32_t _sd_ble_tx_packet_count_get(uint16_t conn_handle, uint8_t * p_count)
  153. {
  154. uint8_t * p_buffer;
  155. uint32_t buffer_length;
  156. tx_buf_alloc(&p_buffer, &buffer_length);
  157. mp_out_params[0] = p_count;
  158. const uint32_t err_code = ble_tx_packet_count_get_req_enc(conn_handle,
  159. p_count,
  160. &(p_buffer[1]),
  161. &buffer_length);
  162. APP_ERROR_CHECK(err_code);
  163. //@note: Increment buffer length as internally managed packet type field must be included.
  164. return ser_sd_transport_cmd_write(p_buffer,
  165. (++buffer_length),
  166. tx_packet_count_get_rsp_dec);
  167. }
  168. #endif
  169. /**@brief Command response callback function for @ref sd_ble_uuid_vs_add BLE command.
  170. *
  171. * Callback for decoding the output parameters and the command response return code.
  172. *
  173. * @param[in] p_buffer Pointer to begin of command response buffer.
  174. * @param[in] length Length of data in bytes.
  175. *
  176. * @return Decoded command response return code.
  177. */
  178. static uint32_t uuid_vs_add_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  179. {
  180. uint32_t result_code;
  181. const uint32_t err_code = ble_uuid_vs_add_rsp_dec(p_buffer,
  182. length,
  183. (uint8_t * *)&mp_out_params[0],
  184. &result_code);
  185. //@note: Should never fail.
  186. APP_ERROR_CHECK(err_code);
  187. return result_code;
  188. }
  189. #ifndef _sd_ble_uuid_vs_add
  190. #define _sd_ble_uuid_vs_add sd_ble_uuid_vs_add
  191. #endif
  192. uint32_t _sd_ble_uuid_vs_add(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type)
  193. {
  194. uint8_t * p_buffer;
  195. uint32_t buffer_length;
  196. tx_buf_alloc(&p_buffer, &buffer_length);
  197. mp_out_params[0] = p_uuid_type;
  198. const uint32_t err_code = ble_uuid_vs_add_req_enc(p_vs_uuid, p_uuid_type,
  199. &(p_buffer[1]),
  200. &buffer_length);
  201. APP_ERROR_CHECK(err_code);
  202. //@note: Increment buffer length as internally managed packet type field must be included.
  203. return ser_sd_transport_cmd_write(p_buffer,
  204. (++buffer_length),
  205. uuid_vs_add_rsp_dec);
  206. }
  207. /**@brief Command response callback function for @ref sd_ble_uuid_decode BLE command.
  208. *
  209. * Callback for decoding the output parameters and the command response return code.
  210. *
  211. * @param[in] p_buffer Pointer to begin of command response buffer.
  212. * @param[in] length Length of data in bytes.
  213. *
  214. * @return Decoded command response return code.
  215. */
  216. static uint32_t uuid_decode_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  217. {
  218. uint32_t result_code;
  219. const uint32_t err_code = ble_uuid_decode_rsp_dec(p_buffer,
  220. length,
  221. (ble_uuid_t * *)&mp_out_params[0],
  222. &result_code);
  223. //@note: Should never fail.
  224. APP_ERROR_CHECK(err_code);
  225. return result_code;
  226. }
  227. #ifndef _sd_ble_uuid_decode
  228. #define _sd_ble_uuid_decode sd_ble_uuid_decode
  229. #endif
  230. uint32_t _sd_ble_uuid_decode(uint8_t uuid_le_len,
  231. uint8_t const * const p_uuid_le,
  232. ble_uuid_t * const p_uuid)
  233. {
  234. uint8_t * p_buffer;
  235. uint32_t buffer_length;
  236. tx_buf_alloc(&p_buffer, &buffer_length);
  237. mp_out_params[0] = p_uuid;
  238. const uint32_t err_code = ble_uuid_decode_req_enc(uuid_le_len, p_uuid_le, p_uuid,
  239. &(p_buffer[1]),
  240. &buffer_length);
  241. APP_ERROR_CHECK(err_code);
  242. //@note: Increment buffer length as internally managed packet type field must be included.
  243. return ser_sd_transport_cmd_write(p_buffer,
  244. (++buffer_length),
  245. uuid_decode_rsp_dec);
  246. }
  247. /**@brief Command response callback function for @ref sd_ble_version_get BLE command.
  248. *
  249. * Callback for decoding the output parameters and the command response return code.
  250. *
  251. * @param[in] p_buffer Pointer to begin of command response buffer.
  252. * @param[in] length Length of data in bytes.
  253. *
  254. * @return Decoded command response return code.
  255. */
  256. static uint32_t version_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  257. {
  258. uint32_t result_code;
  259. const uint32_t err_code = ble_version_get_rsp_dec(p_buffer,
  260. length,
  261. (ble_version_t *)mp_out_params[0],
  262. &result_code);
  263. //@note: Should never fail.
  264. APP_ERROR_CHECK(err_code);
  265. return result_code;
  266. }
  267. #ifndef _sd_ble_version_get
  268. #define _sd_ble_version_get sd_ble_version_get
  269. #endif
  270. uint32_t _sd_ble_version_get(ble_version_t * p_version)
  271. {
  272. uint8_t * p_buffer;
  273. uint32_t buffer_length;
  274. tx_buf_alloc(&p_buffer, &buffer_length);
  275. mp_out_params[0] = p_version;
  276. const uint32_t err_code = ble_version_get_req_enc(p_version,
  277. &(p_buffer[1]),
  278. &buffer_length);
  279. APP_ERROR_CHECK(err_code);
  280. //@note: Increment buffer length as internally managed packet type field must be included.
  281. return ser_sd_transport_cmd_write(p_buffer,
  282. (++buffer_length),
  283. version_get_rsp_dec);
  284. }
  285. /**@brief Command response callback function for @ref sd_ble_opt_get BLE command.
  286. *
  287. * Callback for decoding the output parameters and the command response return code.
  288. *
  289. * @param[in] p_buffer Pointer to begin of command response buffer.
  290. * @param[in] length Length of data in bytes.
  291. *
  292. * @return Decoded command response return code.
  293. */
  294. static uint32_t opt_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  295. {
  296. uint32_t result_code;
  297. uint32_t uint32_param;
  298. uint32_t err_code = ble_opt_get_rsp_dec(p_buffer,
  299. length,
  300. &uint32_param,
  301. (ble_opt_t *)mp_out_params[0],
  302. &result_code);
  303. APP_ERROR_CHECK(err_code);
  304. if ((result_code == NRF_SUCCESS) && (m_uint32_param != uint32_param)) // decoded id should be the same as encoded one
  305. {
  306. err_code = NRF_ERROR_INVALID_PARAM;
  307. }
  308. APP_ERROR_CHECK(err_code);
  309. return result_code;
  310. }
  311. #ifndef _sd_ble_opt_get
  312. #define _sd_ble_opt_get sd_ble_opt_get
  313. #endif
  314. uint32_t _sd_ble_opt_get(uint32_t opt_id, ble_opt_t *p_opt)
  315. {
  316. uint8_t * p_buffer;
  317. uint32_t buffer_length;
  318. tx_buf_alloc(&p_buffer, &buffer_length);
  319. mp_out_params[0] = p_opt;
  320. m_uint32_param = opt_id;
  321. const uint32_t err_code = ble_opt_get_req_enc(opt_id,
  322. p_opt,
  323. &(p_buffer[1]),
  324. &buffer_length);
  325. APP_ERROR_CHECK(err_code);
  326. //@note: Increment buffer length as internally managed packet type field must be included.
  327. return ser_sd_transport_cmd_write(p_buffer,
  328. (++buffer_length),
  329. opt_get_rsp_dec);
  330. }
  331. /**@brief Command response callback function for @ref sd_ble_opt_set BLE command.
  332. *
  333. * Callback for decoding the output parameters and the command response return code.
  334. *
  335. * @param[in] p_buffer Pointer to begin of command response buffer.
  336. * @param[in] length Length of data in bytes.
  337. *
  338. * @return Decoded command response return code.
  339. */
  340. static uint32_t opt_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  341. {
  342. uint32_t result_code;
  343. const uint32_t err_code = ble_opt_set_rsp_dec(p_buffer,
  344. length,
  345. &result_code);
  346. APP_ERROR_CHECK(err_code);
  347. return result_code;
  348. }
  349. #ifndef _sd_ble_opt_set
  350. #define _sd_ble_opt_set sd_ble_opt_set
  351. #endif
  352. uint32_t _sd_ble_opt_set(uint32_t opt_id, ble_opt_t const *p_opt)
  353. {
  354. uint8_t * p_buffer;
  355. uint32_t buffer_length;
  356. tx_buf_alloc(&p_buffer, &buffer_length);
  357. const uint32_t err_code = ble_opt_set_req_enc(opt_id,
  358. p_opt,
  359. &(p_buffer[1]),
  360. &buffer_length);
  361. APP_ERROR_CHECK(err_code);
  362. //@note: Increment buffer length as internally managed packet type field must be included.
  363. return ser_sd_transport_cmd_write(p_buffer,
  364. (++buffer_length),
  365. opt_set_rsp_dec);
  366. }
  367. /**@brief Command response callback function for @ref sd_ble_enable BLE command.
  368. *
  369. * Callback for decoding the output parameters and the command response return code.
  370. *
  371. * @param[in] p_buffer Pointer to begin of command response buffer.
  372. * @param[in] length Length of data in bytes.
  373. *
  374. * @return Decoded command response return code.
  375. */
  376. static uint32_t enable_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  377. {
  378. uint32_t result_code;
  379. const uint32_t err_code = ble_enable_rsp_dec(p_buffer,
  380. length,
  381. &result_code);
  382. //@note: Should never fail.
  383. APP_ERROR_CHECK(err_code);
  384. return result_code;
  385. }
  386. #ifndef _sd_ble_enable
  387. #define _sd_ble_enable sd_ble_enable
  388. #endif
  389. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  390. uint32_t _sd_ble_enable(ble_enable_params_t * p_params, uint32_t * p_app_ram_base)
  391. {
  392. uint8_t * p_buffer;
  393. uint32_t buffer_length;
  394. //Ignore ram_base parameter
  395. (void)p_app_ram_base;
  396. app_ble_gap_sec_keys_init();
  397. tx_buf_alloc(&p_buffer, &buffer_length);
  398. mp_out_params[0] = p_params;
  399. const uint32_t err_code = ble_enable_req_enc(p_params,
  400. &(p_buffer[1]),
  401. &buffer_length);
  402. APP_ERROR_CHECK(err_code);
  403. //@note: Increment buffer length as internally managed packet type field must be included.
  404. return ser_sd_transport_cmd_write(p_buffer,
  405. (++buffer_length),
  406. enable_rsp_dec);
  407. }
  408. #else
  409. uint32_t _sd_ble_enable(uint32_t * p_app_ram_base)
  410. {
  411. uint8_t * p_buffer;
  412. uint32_t buffer_length;
  413. //Ignore ram_base parameter
  414. (void)p_app_ram_base;
  415. app_ble_gap_sec_keys_init();
  416. tx_buf_alloc(&p_buffer, &buffer_length);
  417. const uint32_t err_code = ble_enable_req_enc(&(p_buffer[1]),
  418. &buffer_length);
  419. APP_ERROR_CHECK(err_code);
  420. //@note: Increment buffer length as internally managed packet type field must be included.
  421. return ser_sd_transport_cmd_write(p_buffer,
  422. (++buffer_length),
  423. enable_rsp_dec);
  424. }
  425. #endif
  426. /**@brief Command response callback function for @ref sd_ble_user_mem_reply BLE command.
  427. *
  428. * Callback for decoding the output parameters and the command response return code.
  429. *
  430. * @param[in] p_buffer Pointer to begin of command response buffer.
  431. * @param[in] length Length of data in bytes.
  432. *
  433. * @return Decoded command response return code.
  434. */
  435. static uint32_t user_mem_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  436. {
  437. uint32_t result_code;
  438. uint32_t err_code = ble_user_mem_reply_rsp_dec(p_buffer,
  439. length,
  440. &result_code);
  441. APP_ERROR_CHECK(err_code);
  442. if ((result_code != NRF_SUCCESS) &&
  443. (m_output_params.ble_user_mem_reply_out_params.context_allocated))
  444. {
  445. err_code = app_ble_user_mem_context_destroy(
  446. m_output_params.ble_user_mem_reply_out_params.conn_handle);
  447. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  448. }
  449. return result_code;
  450. }
  451. #ifndef _sd_ble_user_mem_reply
  452. #define _sd_ble_user_mem_reply sd_ble_user_mem_reply
  453. #endif
  454. uint32_t _sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t const *p_block)
  455. {
  456. uint8_t * p_buffer;
  457. uint32_t buffer_length, user_mem_table_index;
  458. uint32_t err_code = NRF_SUCCESS;
  459. tx_buf_alloc(&p_buffer, &buffer_length);
  460. // Prepare User Memory Block context for later synchronization when SoftDevice updates
  461. // the data in the memory block
  462. if (p_block != NULL)
  463. {
  464. err_code = app_ble_user_mem_context_create(conn_handle, &user_mem_table_index);
  465. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  466. m_app_user_mem_table[user_mem_table_index].mem_block.len = p_block->len;
  467. m_app_user_mem_table[user_mem_table_index].mem_block.p_mem = p_block->p_mem;
  468. // Save connection handle and context allocation flag for case if context destroy was needed
  469. m_output_params.ble_user_mem_reply_out_params.conn_handle = conn_handle;
  470. m_output_params.ble_user_mem_reply_out_params.context_allocated = 1;
  471. }
  472. else
  473. {
  474. m_output_params.ble_user_mem_reply_out_params.context_allocated = 0;
  475. }
  476. err_code = ble_user_mem_reply_req_enc(conn_handle,
  477. p_block,
  478. &(p_buffer[1]),
  479. &buffer_length);
  480. APP_ERROR_CHECK(err_code);
  481. //@note: Increment buffer length as internally managed packet type field must be included.
  482. return ser_sd_transport_cmd_write(p_buffer,
  483. (++buffer_length),
  484. user_mem_reply_rsp_dec);
  485. }
  486. #if NRF_SD_BLE_API_VERSION >= 4
  487. /**@brief Command response callback function for @ref sd_ble_cfg_set BLE command.
  488. *
  489. * Callback for decoding the output parameters and the command response return code.
  490. *
  491. * @param[in] p_buffer Pointer to begin of command response buffer.
  492. * @param[in] length Length of data in bytes.
  493. *
  494. * @return Decoded command response return code.
  495. */
  496. static uint32_t cfg_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  497. {
  498. uint32_t result_code;
  499. const uint32_t err_code = ble_cfg_set_rsp_dec(p_buffer,
  500. length,
  501. &result_code);
  502. //@note: Should never fail.
  503. APP_ERROR_CHECK(err_code);
  504. return result_code;
  505. }
  506. #ifndef _sd_ble_cfg_set
  507. #define _sd_ble_cfg_set sd_ble_cfg_set
  508. #endif
  509. uint32_t _sd_ble_cfg_set(uint32_t cfg_id, ble_cfg_t const * p_cfg, uint32_t app_ram_base)
  510. {
  511. uint8_t * p_buffer;
  512. uint32_t buffer_length;
  513. //Ignore ram_base parameter
  514. (void)app_ram_base;
  515. tx_buf_alloc(&p_buffer, &buffer_length);
  516. const uint32_t err_code = ble_cfg_set_req_enc(cfg_id, p_cfg,
  517. &(p_buffer[1]),
  518. &buffer_length);
  519. APP_ERROR_CHECK(err_code);
  520. //@note: Increment buffer length as internally managed packet type field must be included.
  521. return ser_sd_transport_cmd_write(p_buffer,
  522. (++buffer_length),
  523. cfg_set_rsp_dec);
  524. }
  525. #endif