app_mw_ble_gap.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043
  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_gap.h"
  41. #include <stdint.h>
  42. #include <string.h>
  43. #include "ble_serialization.h"
  44. #include "ser_sd_transport.h"
  45. #include "ble_gap_app.h"
  46. #include "app_error.h"
  47. #include "app_ble_gap_sec_keys.h"
  48. #include "ser_config.h"
  49. extern ser_ble_gap_app_keyset_t m_app_keys_table[SER_MAX_CONNECTIONS];
  50. /**@brief Structure containing @ref sd_ble_gap_device_name_get output parameters. */
  51. typedef struct
  52. {
  53. uint8_t * p_dev_name; /**< @ref sd_ble_gap_device_name_get p_dev_name output parameter. */
  54. uint16_t * p_len; /**< @ref sd_ble_gap_device_name_get p_len output parameter. */
  55. } gap_device_name_get_output_params_t;
  56. /**@brief Structure containing @ref sd_ble_gap_appearance_get output parameters. */
  57. typedef struct
  58. {
  59. uint16_t * p_appearance; /**< @ref sd_ble_gap_appearance_get p_appearance output parameter. */
  60. } gap_appearance_get_output_params_t;
  61. /**@brief Structure containing @ref sd_ble_gap_ppcp_get output parameters. */
  62. typedef struct
  63. {
  64. ble_gap_conn_params_t * p_conn_params; /**< @ref sd_ble_gap_ppcp_get p_conn_params output parameter. */
  65. } gap_ppcp_get_out_params_t;
  66. /**@brief Structure containing @ref sd_ble_gap_sec_params_reply output parameters. */
  67. typedef struct
  68. {
  69. ble_gap_sec_keyset_t const * p_sec_keyset; /**< @ref sd_ble_gap_sec_params_reply p_sec_keyset output parameter. */
  70. uint16_t conn_handle; /**< @ref sd_ble_gap_sec_params_reply p_conn_handle output parameter. */
  71. } gap_sec_params_reply_out_params_t;
  72. /**@brief Union containing BLE command output parameters. */
  73. typedef union
  74. {
  75. gap_device_name_get_output_params_t gap_device_name_get_out_params; /**< @ref sd_ble_gap_device_name_get output parameters. */
  76. gap_appearance_get_output_params_t gap_appearance_get_out_params; /**< @ref sd_ble_gap_appearance_get output parameters. */
  77. gap_ppcp_get_out_params_t gap_ppcp_get_out_params; /**< @ref sd_ble_gap_ppcp_get output parameters. */
  78. gap_sec_params_reply_out_params_t gap_sec_params_reply_out_params;/**< @ref sd_ble_sec_params_reply output parameters. */
  79. } gap_command_output_params_t;
  80. static gap_command_output_params_t m_output_params; /**< BLE command output parameters. */
  81. static void * mp_out_params[3];
  82. static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len)
  83. {
  84. uint32_t err_code;
  85. do
  86. {
  87. err_code = ser_sd_transport_tx_alloc(p_data, p_len);
  88. }
  89. while (err_code != NRF_SUCCESS);
  90. *p_data[0] = SER_PKT_TYPE_CMD;
  91. *p_len -= 1;
  92. }
  93. /**@brief Command response callback function for @ref sd_ble_gap_adv_start BLE command.
  94. *
  95. * Callback for decoding the command response return code.
  96. *
  97. * @param[in] p_buffer Pointer to begin of command response buffer.
  98. * @param[in] length Length of data in bytes.
  99. *
  100. * @return Decoded command response return code.
  101. */
  102. static uint32_t gap_adv_start_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  103. {
  104. uint32_t result_code;
  105. const uint32_t err_code = ble_gap_adv_start_rsp_dec(p_buffer, length, &result_code);
  106. APP_ERROR_CHECK(err_code);
  107. return result_code;
  108. }
  109. #ifndef _sd_ble_gap_adv_start
  110. #define _sd_ble_gap_adv_start sd_ble_gap_adv_start
  111. #endif
  112. uint32_t _sd_ble_gap_adv_start(
  113. #if NRF_SD_BLE_API_VERSION > 5
  114. uint8_t adv_handle
  115. #else
  116. ble_gap_adv_params_t const * const p_adv_params
  117. #endif
  118. #if NRF_SD_BLE_API_VERSION >= 4
  119. ,uint8_t conn_cfg_tag
  120. #endif
  121. )
  122. {
  123. uint8_t * p_buffer;
  124. uint32_t buffer_length = 0;
  125. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  126. const uint32_t err_code = ble_gap_adv_start_req_enc(
  127. #if NRF_SD_BLE_API_VERSION > 5
  128. adv_handle,
  129. #else
  130. p_adv_params,
  131. #endif
  132. #if NRF_SD_BLE_API_VERSION >= 4
  133. conn_cfg_tag,
  134. #endif
  135. &(p_buffer[1]),
  136. &buffer_length);
  137. APP_ERROR_CHECK(err_code);
  138. //@note: Increment buffer length as internally managed packet type field must be included.
  139. return ser_sd_transport_cmd_write(p_buffer,
  140. (++buffer_length),
  141. gap_adv_start_rsp_dec);
  142. }
  143. /**@brief Command response callback function for @ref ble_gap_device_name_get_req_enc BLE command.
  144. *
  145. * Callback for decoding the output parameters and the command response return code.
  146. *
  147. * @param[in] p_buffer Pointer to begin of command response buffer.
  148. * @param[in] length Length of data in bytes.
  149. *
  150. * @return Decoded command response return code.
  151. */
  152. static uint32_t gap_device_name_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  153. {
  154. uint32_t result_code;
  155. const uint32_t err_code =
  156. ble_gap_device_name_get_rsp_dec(p_buffer,
  157. length,
  158. m_output_params.gap_device_name_get_out_params.p_dev_name,
  159. m_output_params.gap_device_name_get_out_params.p_len,
  160. &result_code);
  161. APP_ERROR_CHECK(err_code);
  162. return result_code;
  163. }
  164. #ifndef _sd_ble_gap_device_name_get
  165. #define _sd_ble_gap_device_name_get sd_ble_gap_device_name_get
  166. #endif
  167. uint32_t _sd_ble_gap_device_name_get(uint8_t * const p_dev_name, uint16_t * const p_len)
  168. {
  169. uint8_t * p_buffer;
  170. uint32_t buffer_length = 0;
  171. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  172. m_output_params.gap_device_name_get_out_params.p_dev_name = p_dev_name;
  173. m_output_params.gap_device_name_get_out_params.p_len = p_len;
  174. const uint32_t err_code = ble_gap_device_name_get_req_enc(p_dev_name,
  175. p_len,
  176. &(p_buffer[1]),
  177. &buffer_length);
  178. //@note: Should never fail.
  179. APP_ERROR_CHECK(err_code);
  180. //@note: Increment buffer length as internally managed packet type field must be included.
  181. return ser_sd_transport_cmd_write(p_buffer,
  182. (++buffer_length),
  183. gap_device_name_get_rsp_dec);
  184. }
  185. /**@brief Command response callback function for @ref sd_ble_gap_appearance_get BLE command.
  186. *
  187. * Callback for decoding the output parameters and the command response return code.
  188. *
  189. * @param[in] p_buffer Pointer to begin of command response buffer.
  190. * @param[in] length Length of data in bytes.
  191. *
  192. * @return Decoded command response return code.
  193. */
  194. static uint32_t gap_appearance_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  195. {
  196. uint32_t result_code;
  197. const uint32_t err_code =
  198. ble_gap_appearance_get_rsp_dec(p_buffer,
  199. length,
  200. m_output_params.gap_appearance_get_out_params.p_appearance,
  201. &result_code);
  202. //@note: Should never fail.
  203. APP_ERROR_CHECK(err_code);
  204. return result_code;
  205. }
  206. #ifndef _sd_ble_gap_appearance_get
  207. #define _sd_ble_gap_appearance_get sd_ble_gap_appearance_get
  208. #endif
  209. uint32_t _sd_ble_gap_appearance_get(uint16_t * const p_appearance)
  210. {
  211. uint8_t * p_buffer;
  212. uint32_t buffer_length = 0;
  213. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  214. m_output_params.gap_appearance_get_out_params.p_appearance = p_appearance;
  215. const uint32_t err_code = ble_gap_appearance_get_req_enc(p_appearance,
  216. &(p_buffer[1]),
  217. &buffer_length);
  218. //@note: Should never fail.
  219. APP_ERROR_CHECK(err_code);
  220. //@note: Increment buffer length as internally managed packet type field must be included.
  221. return ser_sd_transport_cmd_write(p_buffer,
  222. (++buffer_length),
  223. gap_appearance_get_rsp_dec);
  224. }
  225. /**@brief Command response callback function for @ref sd_ble_gap_device_name_set BLE command.
  226. *
  227. * Callback for decoding the command response return code.
  228. *
  229. * @param[in] p_buffer Pointer to begin of command response buffer.
  230. * @param[in] length Length of data in bytes.
  231. *
  232. * @return Decoded command response return code.
  233. */
  234. static uint32_t gap_device_name_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  235. {
  236. uint32_t result_code;
  237. const uint32_t err_code = ble_gap_device_name_set_rsp_dec(p_buffer, length, &result_code);
  238. APP_ERROR_CHECK(err_code);
  239. return result_code;
  240. }
  241. #ifndef _sd_ble_gap_device_name_set
  242. #define _sd_ble_gap_device_name_set sd_ble_gap_device_name_set
  243. #endif
  244. uint32_t _sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const * const p_write_perm,
  245. uint8_t const * const p_dev_name,
  246. uint16_t len)
  247. {
  248. uint8_t * p_buffer;
  249. uint32_t buffer_length = 0;
  250. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  251. const uint32_t err_code = ble_gap_device_name_set_req_enc(p_write_perm,
  252. p_dev_name,
  253. len,
  254. &(p_buffer[1]),
  255. &buffer_length);
  256. //@note: Should never fail.
  257. APP_ERROR_CHECK(err_code);
  258. //@note: Increment buffer length as internally managed packet type field must be included.
  259. return ser_sd_transport_cmd_write(p_buffer,
  260. (++buffer_length),
  261. gap_device_name_set_rsp_dec);
  262. }
  263. /**@brief Command response callback function for @ref sd_ble_gap_appearance_set BLE command.
  264. *
  265. * Callback for decoding the command response return code.
  266. *
  267. * @param[in] p_buffer Pointer to begin of command response buffer.
  268. * @param[in] length Length of data in bytes.
  269. *
  270. * @return Decoded command response return code.
  271. */
  272. static uint32_t gap_appearance_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  273. {
  274. uint32_t result_code;
  275. const uint32_t err_code = ble_gap_appearance_set_rsp_dec(p_buffer, length, &result_code);
  276. APP_ERROR_CHECK(err_code);
  277. return result_code;
  278. }
  279. #ifndef _sd_ble_gap_appearance_set
  280. #define _sd_ble_gap_appearance_set sd_ble_gap_appearance_set
  281. #endif
  282. uint32_t _sd_ble_gap_appearance_set(uint16_t appearance)
  283. {
  284. uint8_t * p_buffer;
  285. uint32_t buffer_length = 0;
  286. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  287. const uint32_t err_code = ble_gap_appearance_set_req_enc(appearance,
  288. &(p_buffer[1]),
  289. &buffer_length);
  290. //@note: Should never fail.
  291. APP_ERROR_CHECK(err_code);
  292. //@note: Increment buffer length as internally managed packet type field must be included.
  293. return ser_sd_transport_cmd_write(p_buffer,
  294. (++buffer_length),
  295. gap_appearance_set_rsp_dec);
  296. }
  297. /**@brief Command response callback function for @ref sd_ble_gap_ppcp_set BLE command.
  298. *
  299. * Callback for decoding the command response return code.
  300. *
  301. * @param[in] p_buffer Pointer to begin of command response buffer.
  302. * @param[in] length Length of data in bytes.
  303. *
  304. * @return Decoded command response return code.
  305. */
  306. static uint32_t gap_ppcp_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  307. {
  308. uint32_t result_code;
  309. const uint32_t err_code = ble_gap_ppcp_set_rsp_dec(p_buffer, length, &result_code);
  310. APP_ERROR_CHECK(err_code);
  311. return result_code;
  312. }
  313. #ifndef _sd_ble_gap_ppcp_set
  314. #define _sd_ble_gap_ppcp_set sd_ble_gap_ppcp_set
  315. #endif
  316. uint32_t _sd_ble_gap_ppcp_set(ble_gap_conn_params_t const * const p_conn_params)
  317. {
  318. uint8_t * p_buffer;
  319. uint32_t buffer_length = 0;
  320. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  321. const uint32_t err_code = ble_gap_ppcp_set_req_enc(p_conn_params,
  322. &(p_buffer[1]),
  323. &buffer_length);
  324. //@note: Should never fail.
  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. gap_ppcp_set_rsp_dec);
  330. }
  331. /**@brief Command response callback function for @ref sd_ble_gap_adv_data_set BLE command.
  332. *
  333. * Callback for decoding 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. #if NRF_SD_BLE_API_VERSION <= 5
  341. static uint32_t gap_adv_data_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  342. {
  343. uint32_t result_code;
  344. const uint32_t err_code = ble_gap_adv_data_set_rsp_dec(p_buffer, length, &result_code);
  345. APP_ERROR_CHECK(err_code);
  346. return result_code;
  347. }
  348. #ifndef _sd_ble_gap_adv_data_set
  349. #define _sd_ble_gap_adv_data_set sd_ble_gap_adv_data_set
  350. #endif
  351. uint32_t _sd_ble_gap_adv_data_set(uint8_t const * const p_data,
  352. uint8_t dlen,
  353. uint8_t const * const p_sr_data,
  354. uint8_t srdlen)
  355. {
  356. uint8_t * p_buffer;
  357. uint32_t buffer_length = 0;
  358. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  359. const uint32_t err_code = ble_gap_adv_data_set_req_enc(p_data,
  360. dlen,
  361. p_sr_data,
  362. srdlen,
  363. &(p_buffer[1]),
  364. &buffer_length);
  365. APP_ERROR_CHECK(err_code);
  366. //@note: Increment buffer length as internally managed packet type field must be included.
  367. return ser_sd_transport_cmd_write(p_buffer,
  368. (++buffer_length),
  369. gap_adv_data_set_rsp_dec);
  370. }
  371. #endif
  372. /**@brief Command response callback function for @ref sd_ble_gap_conn_param_update BLE command.
  373. *
  374. * Callback for decoding the command response return code.
  375. *
  376. * @param[in] p_buffer Pointer to begin of command response buffer.
  377. * @param[in] length Length of data in bytes.
  378. *
  379. * @return Decoded command response return code.
  380. */
  381. static uint32_t gap_conn_param_update_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  382. {
  383. uint32_t result_code;
  384. const uint32_t err_code = ble_gap_conn_param_update_rsp_dec(p_buffer, length, &result_code);
  385. APP_ERROR_CHECK(err_code);
  386. return result_code;
  387. }
  388. #ifndef _sd_ble_gap_conn_param_update
  389. #define _sd_ble_gap_conn_param_update sd_ble_gap_conn_param_update
  390. #endif
  391. uint32_t _sd_ble_gap_conn_param_update(uint16_t conn_handle,
  392. ble_gap_conn_params_t const * const p_conn_params)
  393. {
  394. uint8_t * p_buffer;
  395. uint32_t buffer_length = 0;
  396. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  397. const uint32_t err_code = ble_gap_conn_param_update_req_enc(conn_handle,
  398. p_conn_params,
  399. &(p_buffer[1]),
  400. &buffer_length);
  401. APP_ERROR_CHECK(err_code);
  402. //@note: Increment buffer length as internally managed packet type field must be included.
  403. return ser_sd_transport_cmd_write(p_buffer,
  404. (++buffer_length),
  405. gap_conn_param_update_rsp_dec);
  406. }
  407. /**@brief Command response callback function for @ref sd_ble_gap_disconnect BLE command.
  408. *
  409. * Callback for decoding the command response return code.
  410. *
  411. * @param[in] p_buffer Pointer to begin of command response buffer.
  412. * @param[in] length Length of data in bytes.
  413. *
  414. * @return Decoded command response return code.
  415. */
  416. static uint32_t gap_disconnect_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  417. {
  418. uint32_t result_code;
  419. const uint32_t err_code = ble_gap_disconnect_rsp_dec(p_buffer, length, &result_code);
  420. APP_ERROR_CHECK(err_code);
  421. return result_code;
  422. }
  423. #ifndef _sd_ble_gap_disconnect
  424. #define _sd_ble_gap_disconnect sd_ble_gap_disconnect
  425. #endif
  426. uint32_t _sd_ble_gap_disconnect(uint16_t conn_handle, uint8_t hci_status_code)
  427. {
  428. uint8_t * p_buffer;
  429. uint32_t buffer_length = 0;
  430. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  431. const uint32_t err_code = ble_gap_disconnect_req_enc(conn_handle,
  432. hci_status_code,
  433. &(p_buffer[1]),
  434. &buffer_length);
  435. //@note: Should never fail.
  436. APP_ERROR_CHECK(err_code);
  437. //@note: Increment buffer length as internally managed packet type field must be included.
  438. return ser_sd_transport_cmd_write(p_buffer,
  439. (++buffer_length),
  440. gap_disconnect_rsp_dec);
  441. }
  442. /**@brief Command response callback function for @ref sd_ble_gap_sec_info_reply BLE command.
  443. *
  444. * Callback for decoding the command response return code.
  445. *
  446. * @param[in] p_buffer Pointer to begin of command response buffer.
  447. * @param[in] length Length of data in bytes.
  448. *
  449. * @return Decoded command response return code.
  450. */
  451. static uint32_t gap_sec_info_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  452. {
  453. uint32_t result_code;
  454. const uint32_t err_code = ble_gap_sec_info_reply_rsp_dec(p_buffer, length, &result_code);
  455. APP_ERROR_CHECK(err_code);
  456. return result_code;
  457. }
  458. #ifndef _sd_ble_gap_sec_info_reply
  459. #define _sd_ble_gap_sec_info_reply sd_ble_gap_sec_info_reply
  460. #endif
  461. uint32_t _sd_ble_gap_sec_info_reply(uint16_t conn_handle,
  462. ble_gap_enc_info_t const * p_enc_info,
  463. ble_gap_irk_t const * p_id_info,
  464. ble_gap_sign_info_t const * p_sign_info)
  465. {
  466. uint8_t * p_buffer;
  467. uint32_t buffer_length = 0;
  468. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  469. const uint32_t err_code = ble_gap_sec_info_reply_req_enc(conn_handle,
  470. p_enc_info,
  471. p_id_info,
  472. p_sign_info,
  473. &(p_buffer[1]),
  474. &buffer_length);
  475. APP_ERROR_CHECK(err_code);
  476. //@note: Increment buffer length as internally managed packet type field must be included.
  477. return ser_sd_transport_cmd_write(p_buffer,
  478. (++buffer_length),
  479. gap_sec_info_reply_rsp_dec);
  480. }
  481. /**@brief Command response callback function for @ref sd_ble_gap_sec_params_reply BLE command.
  482. *
  483. * Callback for decoding the command response return code.
  484. *
  485. * @param[in] p_buffer Pointer to begin of command response buffer.
  486. * @param[in] length Length of data in bytes.
  487. *
  488. * @return Decoded command response return code.
  489. */
  490. static uint32_t gap_sec_params_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  491. {
  492. uint32_t result_code = 0;
  493. uint32_t err_code = ble_gap_sec_params_reply_rsp_dec(p_buffer, length,
  494. m_output_params.gap_sec_params_reply_out_params.p_sec_keyset, &result_code);
  495. APP_ERROR_CHECK(err_code);
  496. // If soft device returned error free security context
  497. if (result_code)
  498. {
  499. err_code = app_ble_gap_sec_context_destroy(m_output_params.gap_sec_params_reply_out_params.conn_handle);
  500. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  501. }
  502. return result_code;
  503. }
  504. #ifndef _sd_ble_gap_sec_params_reply
  505. #define _sd_ble_gap_sec_params_reply sd_ble_gap_sec_params_reply
  506. #endif
  507. uint32_t _sd_ble_gap_sec_params_reply(uint16_t conn_handle,
  508. uint8_t sec_status,
  509. ble_gap_sec_params_t const * p_sec_params,
  510. ble_gap_sec_keyset_t const * p_sec_keyset)
  511. {
  512. uint8_t * p_buffer;
  513. uint32_t buffer_length = 0;
  514. uint32_t sec_tab_index = 0;
  515. uint32_t err_code = NRF_SUCCESS;
  516. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  517. m_output_params.gap_sec_params_reply_out_params.p_sec_keyset = p_sec_keyset;
  518. m_output_params.gap_sec_params_reply_out_params.conn_handle = conn_handle;
  519. // First allocate security context for serialization
  520. if (p_sec_keyset)
  521. {
  522. err_code = app_ble_gap_sec_context_create(conn_handle, &sec_tab_index);
  523. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  524. memcpy(&(m_app_keys_table[sec_tab_index].keyset), p_sec_keyset, sizeof(ble_gap_sec_keyset_t));
  525. }
  526. err_code = ble_gap_sec_params_reply_req_enc(conn_handle,
  527. sec_status,
  528. p_sec_params,
  529. p_sec_keyset,
  530. &(p_buffer[1]),
  531. &buffer_length);
  532. APP_ERROR_CHECK(err_code);
  533. //@note: Increment buffer length as internally managed packet type field must be included.
  534. return ser_sd_transport_cmd_write(p_buffer,
  535. (++buffer_length),
  536. gap_sec_params_reply_rsp_dec);
  537. }
  538. /**@brief Command response callback function for @ref sd_ble_gap_ppcp_get BLE command.
  539. *
  540. * Callback for decoding the output parameters and the command response return code.
  541. *
  542. * @param[in] p_buffer Pointer to begin of command response buffer.
  543. * @param[in] length Length of data in bytes.
  544. *
  545. * @return Decoded command response return code.
  546. */
  547. static uint32_t gap_ppcp_get_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  548. {
  549. uint32_t result_code = 0;
  550. const uint32_t err_code = ble_gap_ppcp_get_rsp_dec(
  551. p_buffer,
  552. length,
  553. m_output_params.gap_ppcp_get_out_params.
  554. p_conn_params,
  555. &result_code);
  556. //@note: Should never fail.
  557. APP_ERROR_CHECK(err_code);
  558. return result_code;
  559. }
  560. #ifndef _sd_ble_gap_ppcp_get
  561. #define _sd_ble_gap_ppcp_get sd_ble_gap_ppcp_get
  562. #endif
  563. uint32_t _sd_ble_gap_ppcp_get(ble_gap_conn_params_t * const p_conn_params)
  564. {
  565. uint8_t * p_buffer;
  566. uint32_t buffer_length = 0;
  567. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  568. m_output_params.gap_ppcp_get_out_params.p_conn_params = p_conn_params;
  569. const uint32_t err_code = ble_gap_ppcp_get_req_enc(p_conn_params,
  570. &(p_buffer[1]),
  571. &buffer_length);
  572. //@note: Should never fail.
  573. APP_ERROR_CHECK(err_code);
  574. //@note: Increment buffer length as internally managed packet type field must be included.
  575. return ser_sd_transport_cmd_write(p_buffer,
  576. (++buffer_length),
  577. gap_ppcp_get_reply_rsp_dec);
  578. }
  579. /**@brief Command response callback function for @ref sd_ble_gap_adv_stop BLE command.
  580. *
  581. * Callback for decoding the output parameters and the command response return code.
  582. *
  583. * @param[in] p_buffer Pointer to begin of command response buffer.
  584. * @param[in] length Length of data in bytes.
  585. *
  586. * @return Decoded command response return code.
  587. */
  588. static uint32_t gap_adv_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  589. {
  590. uint32_t result_code = 0;
  591. const uint32_t err_code = ble_gap_adv_stop_rsp_dec(p_buffer,
  592. length,
  593. &result_code);
  594. //@note: Should never fail.
  595. APP_ERROR_CHECK(err_code);
  596. return result_code;
  597. }
  598. #ifndef _sd_ble_gap_adv_stop
  599. #define _sd_ble_gap_adv_stop sd_ble_gap_adv_stop
  600. #endif
  601. uint32_t _sd_ble_gap_adv_stop(
  602. #if NRF_SD_BLE_API_VERSION > 5
  603. uint8_t adv_handle
  604. #else
  605. void
  606. #endif
  607. )
  608. {
  609. uint8_t * p_buffer;
  610. uint32_t buffer_length = 0;
  611. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  612. const uint32_t err_code = ble_gap_adv_stop_req_enc(
  613. #if NRF_SD_BLE_API_VERSION > 5
  614. adv_handle,
  615. #endif
  616. &(p_buffer[1]),
  617. &buffer_length);
  618. //@note: Should never fail.
  619. APP_ERROR_CHECK(err_code);
  620. //@note: Increment buffer length as internally managed packet type field must be included.
  621. return ser_sd_transport_cmd_write(p_buffer,
  622. (++buffer_length),
  623. gap_adv_stop_rsp_dec);
  624. }
  625. /**@brief Command response callback function for @ref sd_ble_gap_auth_key_reply BLE command.
  626. *
  627. * Callback for decoding the output parameters and the command response return code.
  628. *
  629. * @param[in] p_buffer Pointer to begin of command response buffer.
  630. * @param[in] length Length of data in bytes.
  631. *
  632. * @return Decoded command response return code.
  633. */
  634. static uint32_t gap_auth_key_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  635. {
  636. uint32_t result_code = 0;
  637. const uint32_t err_code = ble_gap_auth_key_reply_rsp_dec(p_buffer,
  638. length,
  639. &result_code);
  640. //@note: Should never fail.
  641. APP_ERROR_CHECK(err_code);
  642. return result_code;
  643. }
  644. #ifndef _sd_ble_gap_auth_key_reply
  645. #define _sd_ble_gap_auth_key_reply sd_ble_gap_auth_key_reply
  646. #endif
  647. uint32_t _sd_ble_gap_auth_key_reply(uint16_t conn_handle,
  648. uint8_t key_type,
  649. uint8_t const * const key)
  650. {
  651. uint8_t * p_buffer;
  652. uint32_t buffer_length = 0;
  653. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  654. const uint32_t err_code = ble_gap_auth_key_reply_req_enc(conn_handle, key_type, key,
  655. &(p_buffer[1]), &buffer_length);
  656. //@note: Should never fail.
  657. APP_ERROR_CHECK(err_code);
  658. //@note: Increment buffer length as internally managed packet type field must be included.
  659. return ser_sd_transport_cmd_write(p_buffer,
  660. (++buffer_length),
  661. gap_auth_key_reply_rsp_dec);
  662. }
  663. /**@brief Command response callback function for @ref sd_ble_gap_authenticate BLE command.
  664. *
  665. * Callback for decoding the output parameters and the command response return code.
  666. *
  667. * @param[in] p_buffer Pointer to begin of command response buffer.
  668. * @param[in] length Length of data in bytes.
  669. *
  670. * @return Decoded command response return code.
  671. */
  672. static uint32_t gap_authenticate_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  673. {
  674. uint32_t result_code = 0;
  675. const uint32_t err_code = ble_gap_authenticate_rsp_dec(p_buffer,
  676. length,
  677. &result_code);
  678. //@note: Should never fail.
  679. APP_ERROR_CHECK(err_code);
  680. return result_code;
  681. }
  682. #ifndef _sd_ble_gap_authenticate
  683. #define _sd_ble_gap_authenticate sd_ble_gap_authenticate
  684. #endif
  685. uint32_t _sd_ble_gap_authenticate(uint16_t conn_handle,
  686. ble_gap_sec_params_t const * const p_sec_params)
  687. {
  688. uint8_t * p_buffer;
  689. uint32_t buffer_length = 0;
  690. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  691. const uint32_t err_code = ble_gap_authenticate_req_enc(conn_handle, p_sec_params,
  692. &(p_buffer[1]), &buffer_length);
  693. //@note: Should never fail.
  694. APP_ERROR_CHECK(err_code);
  695. //@note: Increment buffer length as internally managed packet type field must be included.
  696. return ser_sd_transport_cmd_write(p_buffer,
  697. (++buffer_length),
  698. gap_authenticate_rsp_dec);
  699. }
  700. /**@brief Command response callback function for @ref sd_ble_gap_conn_sec_get BLE command.
  701. *
  702. * Callback for decoding the output parameters and the command response return code.
  703. *
  704. * @param[in] p_buffer Pointer to begin of command response buffer.
  705. * @param[in] length Length of data in bytes.
  706. *
  707. * @return Decoded command response return code.
  708. */
  709. static uint32_t gap_conn_sec_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  710. {
  711. uint32_t result_code = 0;
  712. const uint32_t err_code = ble_gap_conn_sec_get_rsp_dec(
  713. p_buffer,
  714. length,
  715. (ble_gap_conn_sec_t * *)&mp_out_params[0
  716. ],
  717. &result_code);
  718. //@note: Should never fail.
  719. APP_ERROR_CHECK(err_code);
  720. return result_code;
  721. }
  722. #ifndef _sd_ble_gap_conn_sec_get
  723. #define _sd_ble_gap_conn_sec_get sd_ble_gap_conn_sec_get
  724. #endif
  725. uint32_t _sd_ble_gap_conn_sec_get(uint16_t conn_handle, ble_gap_conn_sec_t * const p_conn_sec)
  726. {
  727. uint8_t * p_buffer;
  728. uint32_t buffer_length = 0;
  729. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  730. mp_out_params[0] = p_conn_sec;
  731. const uint32_t err_code = ble_gap_conn_sec_get_req_enc(conn_handle, p_conn_sec,
  732. &(p_buffer[1]), &buffer_length);
  733. //@note: Should never fail.
  734. APP_ERROR_CHECK(err_code);
  735. //@note: Increment buffer length as internally managed packet type field must be included.
  736. return ser_sd_transport_cmd_write(p_buffer,
  737. (++buffer_length),
  738. gap_conn_sec_get_rsp_dec);
  739. }
  740. /**@brief Command response callback function for @ref sd_ble_gap_rssi_start BLE command.
  741. *
  742. * Callback for decoding the output parameters and the command response return code.
  743. *
  744. * @param[in] p_buffer Pointer to begin of command response buffer.
  745. * @param[in] length Length of data in bytes.
  746. *
  747. * @return Decoded command response return code.
  748. */
  749. static uint32_t gap_rssi_start_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  750. {
  751. uint32_t result_code = 0;
  752. const uint32_t err_code = ble_gap_rssi_start_rsp_dec(p_buffer,
  753. length,
  754. &result_code);
  755. //@note: Should never fail.
  756. APP_ERROR_CHECK(err_code);
  757. return result_code;
  758. }
  759. #ifndef _sd_ble_gap_rssi_start
  760. #define _sd_ble_gap_rssi_start sd_ble_gap_rssi_start
  761. #endif
  762. uint32_t _sd_ble_gap_rssi_start(uint16_t conn_handle, uint8_t threshold_dbm, uint8_t skip_count)
  763. {
  764. uint8_t * p_buffer;
  765. uint32_t buffer_length = 0;
  766. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  767. const uint32_t err_code = ble_gap_rssi_start_req_enc(conn_handle,
  768. threshold_dbm,
  769. skip_count,
  770. &(p_buffer[1]), &buffer_length);
  771. //@note: Should never fail.
  772. APP_ERROR_CHECK(err_code);
  773. //@note: Increment buffer length as internally managed packet type field must be included.
  774. return ser_sd_transport_cmd_write(p_buffer,
  775. (++buffer_length),
  776. gap_rssi_start_rsp_dec);
  777. }
  778. /**@brief Command response callback function for @ref sd_ble_gap_rssi_stop BLE command.
  779. *
  780. * Callback for decoding the output parameters and the command response return code.
  781. *
  782. * @param[in] p_buffer Pointer to begin of command response buffer.
  783. * @param[in] length Length of data in bytes.
  784. *
  785. * @return Decoded command response return code.
  786. */
  787. static uint32_t gap_rssi_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  788. {
  789. uint32_t result_code = 0;
  790. const uint32_t err_code = ble_gap_rssi_stop_rsp_dec(p_buffer,
  791. length,
  792. &result_code);
  793. //@note: Should never fail.
  794. APP_ERROR_CHECK(err_code);
  795. return result_code;
  796. }
  797. #ifndef _sd_ble_gap_rssi_stop
  798. #define _sd_ble_gap_rssi_stop sd_ble_gap_rssi_stop
  799. #endif
  800. uint32_t _sd_ble_gap_rssi_stop(uint16_t conn_handle)
  801. {
  802. uint8_t * p_buffer;
  803. uint32_t buffer_length = 0;
  804. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  805. const uint32_t err_code = ble_gap_rssi_stop_req_enc(conn_handle,
  806. &(p_buffer[1]), &buffer_length);
  807. //@note: Should never fail.
  808. APP_ERROR_CHECK(err_code);
  809. //@note: Increment buffer length as internally managed packet type field must be included.
  810. return ser_sd_transport_cmd_write(p_buffer,
  811. (++buffer_length),
  812. gap_rssi_stop_rsp_dec);
  813. }
  814. /**@brief Command response callback function for @ref sd_ble_gap_tx_power_set BLE command.
  815. *
  816. * Callback for decoding the output parameters and the command response return code.
  817. *
  818. * @param[in] p_buffer Pointer to begin of command response buffer.
  819. * @param[in] length Length of data in bytes.
  820. *
  821. * @return Decoded command response return code.
  822. */
  823. static uint32_t gap_tx_power_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  824. {
  825. uint32_t result_code = 0;
  826. const uint32_t err_code = ble_gap_tx_power_set_rsp_dec(p_buffer,
  827. length,
  828. &result_code);
  829. //@note: Should never fail.
  830. APP_ERROR_CHECK(err_code);
  831. return result_code;
  832. }
  833. #ifndef _sd_ble_gap_tx_power_set
  834. #define _sd_ble_gap_tx_power_set sd_ble_gap_tx_power_set
  835. #endif
  836. uint32_t _sd_ble_gap_tx_power_set(
  837. #if NRF_SD_BLE_API_VERSION > 5
  838. uint8_t role, uint16_t handle,
  839. #endif
  840. int8_t tx_power)
  841. {
  842. uint8_t * p_buffer;
  843. uint32_t buffer_length = 0;
  844. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  845. #if NRF_SD_BLE_API_VERSION > 5
  846. const uint32_t err_code = ble_gap_tx_power_set_req_enc(role, handle, tx_power,
  847. &(p_buffer[1]), &buffer_length);
  848. #else
  849. const uint32_t err_code = ble_gap_tx_power_set_req_enc(tx_power,
  850. &(p_buffer[1]), &buffer_length);
  851. #endif
  852. //@note: Should never fail.
  853. APP_ERROR_CHECK(err_code);
  854. //@note: Increment buffer length as internally managed packet type field must be included.
  855. return ser_sd_transport_cmd_write(p_buffer,
  856. (++buffer_length),
  857. gap_tx_power_set_rsp_dec);
  858. }
  859. #ifndef S112
  860. /**@brief Command response callback function for @ref sd_ble_gap_scan_stop BLE command.
  861. *
  862. * Callback for decoding the output parameters and the command response return code.
  863. *
  864. * @param[in] p_buffer Pointer to begin of command response buffer.
  865. * @param[in] length Length of data in bytes.
  866. *
  867. * @return Decoded command response return code.
  868. */
  869. static uint32_t gap_scan_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  870. {
  871. uint32_t result_code = 0;
  872. const uint32_t err_code = ble_gap_scan_stop_rsp_dec(p_buffer,
  873. length,
  874. &result_code);
  875. //@note: Should never fail.
  876. APP_ERROR_CHECK(err_code);
  877. return result_code;
  878. }
  879. #ifndef _sd_ble_gap_scan_stop
  880. #define _sd_ble_gap_scan_stop sd_ble_gap_scan_stop
  881. #endif
  882. uint32_t _sd_ble_gap_scan_stop(void)
  883. {
  884. uint8_t * p_buffer;
  885. uint32_t buffer_length = 0;
  886. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  887. const uint32_t err_code = ble_gap_scan_stop_req_enc(&(p_buffer[1]),
  888. &buffer_length);
  889. //@note: Should never fail.
  890. APP_ERROR_CHECK(err_code);
  891. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  892. app_ble_gap_scan_data_unset(true);
  893. #endif
  894. //@note: Increment buffer length as internally managed packet type field must be included.
  895. return ser_sd_transport_cmd_write(p_buffer,
  896. (++buffer_length),
  897. gap_scan_stop_rsp_dec);
  898. }
  899. /**@brief Command response callback function for @ref sd_ble_gap_connect BLE command.
  900. *
  901. * Callback for decoding the output parameters and the command response return code.
  902. *
  903. * @param[in] p_buffer Pointer to begin of command response buffer.
  904. * @param[in] length Length of data in bytes.
  905. *
  906. * @return Decoded command response return code.
  907. */
  908. static uint32_t gap_connect_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  909. {
  910. uint32_t result_code = 0;
  911. const uint32_t err_code = ble_gap_connect_rsp_dec(p_buffer,
  912. length,
  913. &result_code);
  914. //@note: Should never fail.
  915. APP_ERROR_CHECK(err_code);
  916. return result_code;
  917. }
  918. #ifndef _sd_ble_gap_connect
  919. #define _sd_ble_gap_connect sd_ble_gap_connect
  920. #endif
  921. uint32_t _sd_ble_gap_connect(ble_gap_addr_t const * const p_addr,
  922. ble_gap_scan_params_t const * const p_scan_params,
  923. ble_gap_conn_params_t const * const p_conn_params
  924. #if NRF_SD_BLE_API_VERSION >= 4
  925. ,uint8_t conn_cfg_tag
  926. #endif
  927. )
  928. {
  929. uint8_t * p_buffer;
  930. uint32_t buffer_length = 0;
  931. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  932. const uint32_t err_code = ble_gap_connect_req_enc(p_addr,
  933. p_scan_params,
  934. p_conn_params,
  935. #if NRF_SD_BLE_API_VERSION >= 4
  936. conn_cfg_tag,
  937. #endif
  938. &(p_buffer[1]),
  939. &buffer_length);
  940. //@note: Should never fail.
  941. APP_ERROR_CHECK(err_code);
  942. //@note: Increment buffer length as internally managed packet type field must be included.
  943. return ser_sd_transport_cmd_write(p_buffer,
  944. (++buffer_length),
  945. gap_connect_rsp_dec);
  946. }
  947. /**@brief Command response callback function for @ref sd_ble_gap_connect_cancel BLE command.
  948. *
  949. * Callback for decoding the output parameters and the command response return code.
  950. *
  951. * @param[in] p_buffer Pointer to begin of command response buffer.
  952. * @param[in] length Length of data in bytes.
  953. *
  954. * @return Decoded command response return code.
  955. */
  956. static uint32_t gap_connect_cancel_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  957. {
  958. uint32_t result_code = 0;
  959. const uint32_t err_code = ble_gap_connect_cancel_rsp_dec(p_buffer,
  960. length,
  961. &result_code);
  962. //@note: Should never fail.
  963. APP_ERROR_CHECK(err_code);
  964. return result_code;
  965. }
  966. #ifndef _sd_ble_gap_connect_cancel
  967. #define _sd_ble_gap_connect_cancel sd_ble_gap_connect_cancel
  968. #endif
  969. uint32_t _sd_ble_gap_connect_cancel(void)
  970. {
  971. uint8_t * p_buffer;
  972. uint32_t buffer_length = 0;
  973. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  974. const uint32_t err_code = ble_gap_connect_cancel_req_enc(&(p_buffer[1]),
  975. &buffer_length);
  976. //@note: Should never fail.
  977. APP_ERROR_CHECK(err_code);
  978. //@note: Increment buffer length as internally managed packet type field must be included.
  979. return ser_sd_transport_cmd_write(p_buffer,
  980. (++buffer_length),
  981. gap_connect_cancel_rsp_dec);
  982. }
  983. /**@brief Command response callback function for @ref sd_ble_gap_scan_start BLE command.
  984. *
  985. * Callback for decoding the output parameters and the command response return code.
  986. *
  987. * @param[in] p_buffer Pointer to begin of command response buffer.
  988. * @param[in] length Length of data in bytes.
  989. *
  990. * @return Decoded command response return code.
  991. */
  992. static uint32_t gap_scan_start_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  993. {
  994. uint32_t result_code = 0;
  995. const uint32_t err_code = ble_gap_scan_start_rsp_dec(p_buffer,
  996. length,
  997. &result_code);
  998. if (result_code != NRF_SUCCESS)
  999. {
  1000. #if NRF_SD_BLE_API_VERSION > 5
  1001. app_ble_gap_scan_data_unset(true);
  1002. #endif
  1003. }
  1004. //@note: Should never fail.
  1005. APP_ERROR_CHECK(err_code);
  1006. return result_code;
  1007. }
  1008. #ifndef _sd_ble_gap_scan_start
  1009. #define _sd_ble_gap_scan_start sd_ble_gap_scan_start
  1010. #endif
  1011. uint32_t _sd_ble_gap_scan_start(ble_gap_scan_params_t const * const p_scan_params
  1012. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  1013. ,ble_data_t const * p_adv_report_buffer
  1014. #endif
  1015. )
  1016. {
  1017. uint8_t * p_buffer;
  1018. uint32_t buffer_length = 0;
  1019. uint32_t err_code;
  1020. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1021. err_code = ble_gap_scan_start_req_enc(p_scan_params,
  1022. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  1023. p_adv_report_buffer,
  1024. #endif
  1025. &(p_buffer[1]),
  1026. &buffer_length);
  1027. //@note: Should never fail.
  1028. APP_ERROR_CHECK(err_code);
  1029. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  1030. if (p_adv_report_buffer) {
  1031. app_ble_gap_scan_data_set(p_adv_report_buffer->p_data);
  1032. }
  1033. #endif
  1034. //@note: Increment buffer length as internally managed packet type field must be included.
  1035. return ser_sd_transport_cmd_write(p_buffer,
  1036. (++buffer_length),
  1037. gap_scan_start_rsp_dec);
  1038. }
  1039. /**@brief Command response callback function for @ref sd_ble_gap_encrypt BLE command.
  1040. *
  1041. * Callback for decoding the output parameters and the command response return code.
  1042. *
  1043. * @param[in] p_buffer Pointer to begin of command response buffer.
  1044. * @param[in] length Length of data in bytes.
  1045. *
  1046. * @return Decoded command response return code.
  1047. */
  1048. static uint32_t gap_encrypt_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1049. {
  1050. uint32_t result_code = 0;
  1051. const uint32_t err_code = ble_gap_encrypt_rsp_dec(p_buffer,
  1052. length,
  1053. &result_code);
  1054. //@note: Should never fail.
  1055. APP_ERROR_CHECK(err_code);
  1056. return result_code;
  1057. }
  1058. #ifndef _sd_ble_gap_encrypt
  1059. #define _sd_ble_gap_encrypt sd_ble_gap_encrypt
  1060. #endif
  1061. uint32_t _sd_ble_gap_encrypt( uint16_t conn_handle,
  1062. ble_gap_master_id_t const * p_master_id,
  1063. ble_gap_enc_info_t const * p_enc_info)
  1064. {
  1065. uint8_t * p_buffer;
  1066. uint32_t buffer_length = 0;
  1067. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1068. const uint32_t err_code = ble_gap_encrypt_req_enc( conn_handle, p_master_id, p_enc_info, &(p_buffer[1]), &buffer_length );
  1069. //@note: Should never fail.
  1070. APP_ERROR_CHECK(err_code);
  1071. //@note: Increment buffer length as internally managed packet type field must be included.
  1072. return ser_sd_transport_cmd_write(p_buffer,
  1073. (++buffer_length),
  1074. gap_encrypt_rsp_dec);
  1075. }
  1076. #endif //!S112
  1077. /**@brief Command response callback function for @ref sd_ble_gap_rssi_get BLE command.
  1078. *
  1079. * Callback for decoding the output parameters and the command response return code.
  1080. *
  1081. * @param[in] p_buffer Pointer to begin of command response buffer.
  1082. * @param[in] length Length of data in bytes.
  1083. *
  1084. * @return Decoded command response return code.
  1085. */
  1086. static uint32_t gap_rssi_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1087. {
  1088. uint32_t result_code = 0;
  1089. const uint32_t err_code = ble_gap_rssi_get_rsp_dec(p_buffer,
  1090. length,
  1091. (int8_t *) mp_out_params[0],
  1092. #if NRF_SD_BLE_API_VERSION > 5
  1093. (uint8_t *) mp_out_params[1],
  1094. #endif
  1095. &result_code);
  1096. //@note: Should never fail.
  1097. APP_ERROR_CHECK(err_code);
  1098. return result_code;
  1099. }
  1100. #ifndef _sd_ble_gap_rssi_get
  1101. #define _sd_ble_gap_rssi_get sd_ble_gap_rssi_get
  1102. #endif
  1103. uint32_t _sd_ble_gap_rssi_get(uint16_t conn_handle,
  1104. int8_t * p_rssi
  1105. #if NRF_SD_BLE_API_VERSION > 5
  1106. ,uint8_t * p_ch_index
  1107. #endif
  1108. )
  1109. {
  1110. uint8_t * p_buffer;
  1111. uint32_t buffer_length = 0;
  1112. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1113. mp_out_params[0] = p_rssi;
  1114. #if NRF_SD_BLE_API_VERSION > 5
  1115. mp_out_params[1] = p_ch_index;
  1116. const uint32_t err_code = ble_gap_rssi_get_req_enc(conn_handle, p_rssi, p_ch_index, &(p_buffer[1]), &buffer_length);
  1117. #else
  1118. const uint32_t err_code = ble_gap_rssi_get_req_enc(conn_handle, p_rssi, &(p_buffer[1]), &buffer_length);
  1119. #endif
  1120. //@note: Should never fail.
  1121. APP_ERROR_CHECK(err_code);
  1122. //@note: Increment buffer length as internally managed packet type field must be included.
  1123. return ser_sd_transport_cmd_write(p_buffer,
  1124. (++buffer_length),
  1125. gap_rssi_get_rsp_dec);
  1126. }
  1127. /**@brief Command response callback function for @ref sd_ble_gap_keypress_notify BLE command.
  1128. *
  1129. * Callback for decoding the output parameters and the command response return code.
  1130. *
  1131. * @param[in] p_buffer Pointer to begin of command response buffer.
  1132. * @param[in] length Length of data in bytes.
  1133. *
  1134. * @return Decoded command response return code.
  1135. */
  1136. static uint32_t gap_keypress_notify_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1137. {
  1138. uint32_t result_code = 0;
  1139. const uint32_t err_code = ble_gap_keypress_notify_rsp_dec(p_buffer,
  1140. length,
  1141. &result_code);
  1142. //@note: Should never fail.
  1143. APP_ERROR_CHECK(err_code);
  1144. return result_code;
  1145. }
  1146. #ifndef _sd_ble_gap_keypress_notify
  1147. #define _sd_ble_gap_keypress_notify sd_ble_gap_keypress_notify
  1148. #endif
  1149. uint32_t _sd_ble_gap_keypress_notify( uint16_t conn_handle, uint8_t kp_not)
  1150. {
  1151. uint8_t * p_buffer;
  1152. uint32_t buffer_length = 0;
  1153. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1154. const uint32_t err_code = ble_gap_keypress_notify_req_enc( conn_handle, kp_not, &p_buffer[1], &buffer_length );
  1155. //@note: Should never fail.
  1156. APP_ERROR_CHECK(err_code);
  1157. //@note: Increment buffer length as internally managed packet type field must be included.
  1158. return ser_sd_transport_cmd_write(p_buffer,
  1159. (++buffer_length),
  1160. gap_keypress_notify_rsp_dec);
  1161. }
  1162. /**@brief Command response callback function for @ref sd_ble_gap_lesc_dhkey_reply BLE command.
  1163. *
  1164. * Callback for decoding the output parameters and the command response return code.
  1165. *
  1166. * @param[in] p_buffer Pointer to begin of command response buffer.
  1167. * @param[in] length Length of data in bytes.
  1168. *
  1169. * @return Decoded command response return code.
  1170. */
  1171. static uint32_t gap_lesc_dhkey_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1172. {
  1173. uint32_t result_code = 0;
  1174. const uint32_t err_code = ble_gap_lesc_dhkey_reply_rsp_dec(p_buffer,
  1175. length,
  1176. &result_code);
  1177. //@note: Should never fail.
  1178. APP_ERROR_CHECK(err_code);
  1179. return result_code;
  1180. }
  1181. #ifndef _sd_ble_gap_lesc_dhkey_reply
  1182. #define _sd_ble_gap_lesc_dhkey_reply sd_ble_gap_lesc_dhkey_reply
  1183. #endif
  1184. uint32_t _sd_ble_gap_lesc_dhkey_reply( uint16_t conn_handle, ble_gap_lesc_dhkey_t const *p_dhkey)
  1185. {
  1186. uint8_t * p_buffer;
  1187. uint32_t buffer_length = 0;
  1188. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1189. const uint32_t err_code = ble_gap_lesc_dhkey_reply_req_enc( conn_handle, p_dhkey, &(p_buffer[1]), &buffer_length );
  1190. //@note: Should never fail.
  1191. APP_ERROR_CHECK(err_code);
  1192. //@note: Increment buffer length as internally managed packet type field must be included.
  1193. return ser_sd_transport_cmd_write(p_buffer,
  1194. (++buffer_length),
  1195. gap_lesc_dhkey_reply_rsp_dec);
  1196. }
  1197. /**@brief Command response callback function for @ref sd_ble_gap_lesc_oob_data_set BLE command.
  1198. *
  1199. * Callback for decoding the output parameters and the command response return code.
  1200. *
  1201. * @param[in] p_buffer Pointer to begin of command response buffer.
  1202. * @param[in] length Length of data in bytes.
  1203. *
  1204. * @return Decoded command response return code.
  1205. */
  1206. static uint32_t gap_lesc_oob_data_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1207. {
  1208. uint32_t result_code = 0;
  1209. const uint32_t err_code = ble_gap_lesc_oob_data_set_rsp_dec(p_buffer,
  1210. length,
  1211. &result_code);
  1212. //@note: Should never fail.
  1213. APP_ERROR_CHECK(err_code);
  1214. return result_code;
  1215. }
  1216. #ifndef _sd_ble_gap_lesc_oob_data_set
  1217. #define _sd_ble_gap_lesc_oob_data_set sd_ble_gap_lesc_oob_data_set
  1218. #endif
  1219. uint32_t _sd_ble_gap_lesc_oob_data_set(uint16_t conn_handle,
  1220. ble_gap_lesc_oob_data_t const *p_oobd_own,
  1221. ble_gap_lesc_oob_data_t const *p_oobd_peer)
  1222. {
  1223. uint8_t * p_buffer;
  1224. uint32_t buffer_length = 0;
  1225. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1226. const uint32_t err_code = ble_gap_lesc_oob_data_set_req_enc(conn_handle, p_oobd_own, p_oobd_peer,
  1227. &(p_buffer[1]), &buffer_length );
  1228. //@note: Should never fail.
  1229. APP_ERROR_CHECK(err_code);
  1230. //@note: Increment buffer length as internally managed packet type field must be included.
  1231. return ser_sd_transport_cmd_write(p_buffer,
  1232. (++buffer_length),
  1233. gap_lesc_oob_data_set_rsp_dec);
  1234. }
  1235. /**@brief Command response callback function for @ref sd_ble_gap_lesc_oob_data_get BLE command.
  1236. *
  1237. * Callback for decoding the output parameters and the command response return code.
  1238. *
  1239. * @param[in] p_buffer Pointer to begin of command response buffer.
  1240. * @param[in] length Length of data in bytes.
  1241. *
  1242. * @return Decoded command response return code.
  1243. */
  1244. static uint32_t gap_lesc_oob_data_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1245. {
  1246. uint32_t result_code = 0;
  1247. const uint32_t err_code = ble_gap_lesc_oob_data_get_rsp_dec(p_buffer,
  1248. length,
  1249. (ble_gap_lesc_oob_data_t **) &mp_out_params[0],
  1250. &result_code);
  1251. //@note: Should never fail.
  1252. APP_ERROR_CHECK(err_code);
  1253. return result_code;
  1254. }
  1255. #ifndef _sd_ble_gap_lesc_oob_data_get
  1256. #define _sd_ble_gap_lesc_oob_data_get sd_ble_gap_lesc_oob_data_get
  1257. #endif
  1258. uint32_t _sd_ble_gap_lesc_oob_data_get(uint16_t conn_handle,
  1259. ble_gap_lesc_p256_pk_t const *p_pk_own,
  1260. ble_gap_lesc_oob_data_t *p_oobd_own)
  1261. {
  1262. uint8_t * p_buffer;
  1263. uint32_t buffer_length = 0;
  1264. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1265. mp_out_params[0] = p_oobd_own;
  1266. const uint32_t err_code = ble_gap_lesc_oob_data_get_req_enc(conn_handle, p_pk_own, p_oobd_own,
  1267. &(p_buffer[1]), &buffer_length );
  1268. //@note: Should never fail.
  1269. APP_ERROR_CHECK(err_code);
  1270. //@note: Increment buffer length as internally managed packet type field must be included.
  1271. return ser_sd_transport_cmd_write(p_buffer,
  1272. (++buffer_length),
  1273. gap_lesc_oob_data_get_rsp_dec);
  1274. }
  1275. /**@brief Command response callback function for @ref sd_ble_gap_addr_get BLE command.
  1276. *
  1277. * Callback for decoding the output parameters and the command response return code.
  1278. *
  1279. * @param[in] p_buffer Pointer to begin of command response buffer.
  1280. * @param[in] length Length of data in bytes.
  1281. *
  1282. * @return Decoded command response return code.
  1283. */
  1284. static uint32_t gap_addr_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1285. {
  1286. uint32_t result_code = 0;
  1287. const uint32_t err_code = ble_gap_addr_get_rsp_dec(p_buffer,
  1288. length,
  1289. (ble_gap_addr_t *)mp_out_params[0],
  1290. &result_code);
  1291. //@note: Should never fail.
  1292. APP_ERROR_CHECK(err_code);
  1293. return result_code;
  1294. }
  1295. #ifndef _sd_ble_gap_addr_get
  1296. #define _sd_ble_gap_addr_get sd_ble_gap_addr_get
  1297. #endif
  1298. uint32_t _sd_ble_gap_addr_get(ble_gap_addr_t * const p_addr)
  1299. {
  1300. uint8_t * p_buffer;
  1301. uint32_t buffer_length = 0;
  1302. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1303. mp_out_params[0] = p_addr;
  1304. const uint32_t err_code = ble_gap_addr_get_req_enc(p_addr,
  1305. &(p_buffer[1]),
  1306. &buffer_length);
  1307. //@note: Should never fail.
  1308. APP_ERROR_CHECK(err_code);
  1309. //@note: Increment buffer length as internally managed packet type field must be included.
  1310. return ser_sd_transport_cmd_write(p_buffer,
  1311. (++buffer_length),
  1312. gap_addr_get_rsp_dec);
  1313. }
  1314. /**@brief Command response callback function for @ref sd_ble_gap_addr_set BLE command.
  1315. *
  1316. * Callback for decoding the output parameters and the command response return code.
  1317. *
  1318. * @param[in] p_buffer Pointer to begin of command response buffer.
  1319. * @param[in] length Length of data in bytes.
  1320. *
  1321. * @return Decoded command response return code.
  1322. */
  1323. static uint32_t gap_addr_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1324. {
  1325. uint32_t result_code = 0;
  1326. const uint32_t err_code = ble_gap_addr_set_rsp_dec(p_buffer,
  1327. length,
  1328. &result_code);
  1329. //@note: Should never fail.
  1330. APP_ERROR_CHECK(err_code);
  1331. return result_code;
  1332. }
  1333. #ifndef _sd_ble_gap_addr_set
  1334. #define _sd_ble_gap_addr_set sd_ble_gap_addr_set
  1335. #endif
  1336. uint32_t _sd_ble_gap_addr_set(ble_gap_addr_t const * const p_addr)
  1337. {
  1338. uint8_t * p_buffer;
  1339. uint32_t buffer_length = 0;
  1340. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1341. const uint32_t err_code = ble_gap_addr_set_req_enc(p_addr,
  1342. &(p_buffer[1]),
  1343. &buffer_length);
  1344. //@note: Should never fail.
  1345. APP_ERROR_CHECK(err_code);
  1346. //@note: Increment buffer length as internally managed packet type field must be included.
  1347. return ser_sd_transport_cmd_write(p_buffer,
  1348. (++buffer_length),
  1349. gap_addr_set_rsp_dec);
  1350. }
  1351. /**@brief Command response callback function for @ref sd_ble_gap_privacy_set BLE command.
  1352. *
  1353. * Callback for decoding the output parameters and the command response return code.
  1354. *
  1355. * @param[in] p_buffer Pointer to begin of command response buffer.
  1356. * @param[in] length Length of data in bytes.
  1357. *
  1358. * @return Decoded command response return code.
  1359. */
  1360. static uint32_t gap_privacy_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1361. {
  1362. uint32_t result_code = 0;
  1363. const uint32_t err_code = ble_gap_privacy_set_rsp_dec(p_buffer,
  1364. length,
  1365. &result_code);
  1366. //@note: Should never fail.
  1367. APP_ERROR_CHECK(err_code);
  1368. return result_code;
  1369. }
  1370. #ifndef _sd_ble_gap_privacy_set
  1371. #define _sd_ble_gap_privacy_set sd_ble_gap_privacy_set
  1372. #endif
  1373. uint32_t _sd_ble_gap_privacy_set(ble_gap_privacy_params_t const *p_privacy_params)
  1374. {
  1375. uint8_t * p_buffer;
  1376. uint32_t buffer_length = 0;
  1377. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1378. const uint32_t err_code = ble_gap_privacy_set_req_enc(p_privacy_params,
  1379. &(p_buffer[1]), &buffer_length);
  1380. //@note: Should never fail.
  1381. APP_ERROR_CHECK(err_code);
  1382. //@note: Increment buffer length as internally managed packet type field must be included.
  1383. return ser_sd_transport_cmd_write(p_buffer,
  1384. (++buffer_length),
  1385. gap_privacy_set_rsp_dec);
  1386. }
  1387. /**@brief Command response callback function for @ref sd_ble_gap_privacy_get BLE command.
  1388. *
  1389. * Callback for decoding the output parameters and the command response return code.
  1390. *
  1391. * @param[in] p_buffer Pointer to begin of command response buffer.
  1392. * @param[in] length Length of data in bytes.
  1393. *
  1394. * @return Decoded command response return code.
  1395. */
  1396. static uint32_t gap_privacy_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1397. {
  1398. uint32_t result_code = 0;
  1399. const uint32_t err_code = ble_gap_privacy_get_rsp_dec(p_buffer,
  1400. length,
  1401. (ble_gap_privacy_params_t *)mp_out_params[0],
  1402. &result_code);
  1403. //@note: Should never fail.
  1404. APP_ERROR_CHECK(err_code);
  1405. return result_code;
  1406. }
  1407. #ifndef _sd_ble_gap_privacy_get
  1408. #define _sd_ble_gap_privacy_get sd_ble_gap_privacy_get
  1409. #endif
  1410. uint32_t _sd_ble_gap_privacy_get(ble_gap_privacy_params_t *p_privacy_params)
  1411. {
  1412. uint8_t * p_buffer;
  1413. uint32_t buffer_length = 0;
  1414. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1415. mp_out_params[0] = p_privacy_params;
  1416. const uint32_t err_code = ble_gap_privacy_get_req_enc(p_privacy_params,
  1417. &(p_buffer[1]), &buffer_length);
  1418. //@note: Should never fail.
  1419. APP_ERROR_CHECK(err_code);
  1420. //@note: Increment buffer length as internally managed packet type field must be included.
  1421. return ser_sd_transport_cmd_write(p_buffer,
  1422. (++buffer_length),
  1423. gap_privacy_get_rsp_dec);
  1424. }
  1425. /**@brief Command response callback function for @ref sd_ble_gap_whitelist_set BLE command.
  1426. *
  1427. * Callback for decoding the output parameters and the command response return code.
  1428. *
  1429. * @param[in] p_buffer Pointer to begin of command response buffer.
  1430. * @param[in] length Length of data in bytes.
  1431. *
  1432. * @return Decoded command response return code.
  1433. */
  1434. static uint32_t gap_whitelist_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1435. {
  1436. uint32_t result_code = 0;
  1437. const uint32_t err_code = ble_gap_whitelist_set_rsp_dec(p_buffer,
  1438. length,
  1439. &result_code);
  1440. //@note: Should never fail.
  1441. APP_ERROR_CHECK(err_code);
  1442. return result_code;
  1443. }
  1444. #ifndef _sd_ble_gap_whitelist_set
  1445. #define _sd_ble_gap_whitelist_set sd_ble_gap_whitelist_set
  1446. #endif
  1447. uint32_t _sd_ble_gap_whitelist_set(ble_gap_addr_t const * const * pp_wl_addrs, uint8_t len)
  1448. {
  1449. uint8_t * p_buffer;
  1450. uint32_t buffer_length = 0;
  1451. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1452. const uint32_t err_code = ble_gap_whitelist_set_req_enc(pp_wl_addrs, len,
  1453. &(p_buffer[1]), &buffer_length);
  1454. //@note: Should never fail.
  1455. APP_ERROR_CHECK(err_code);
  1456. //@note: Increment buffer length as internally managed packet type field must be included.
  1457. return ser_sd_transport_cmd_write(p_buffer,
  1458. (++buffer_length),
  1459. gap_whitelist_set_rsp_dec);
  1460. }
  1461. /**@brief Command response callback function for @ref sd_ble_gap_device_identities_set BLE command.
  1462. *
  1463. * Callback for decoding the output parameters and the command response return code.
  1464. *
  1465. * @param[in] p_buffer Pointer to begin of command response buffer.
  1466. * @param[in] length Length of data in bytes.
  1467. *
  1468. * @return Decoded command response return code.
  1469. */
  1470. static uint32_t gap_device_identities_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1471. {
  1472. uint32_t result_code = 0;
  1473. const uint32_t err_code = ble_gap_device_identities_set_rsp_dec(p_buffer,
  1474. length,
  1475. &result_code);
  1476. //@note: Should never fail.
  1477. APP_ERROR_CHECK(err_code);
  1478. return result_code;
  1479. }
  1480. #ifndef _sd_ble_gap_device_identities_set
  1481. #define _sd_ble_gap_device_identities_set sd_ble_gap_device_identities_set
  1482. #endif
  1483. uint32_t _sd_ble_gap_device_identities_set(ble_gap_id_key_t const * const * pp_id_keys, ble_gap_irk_t const * const * pp_local_irks, uint8_t len)
  1484. {
  1485. uint8_t * p_buffer;
  1486. uint32_t buffer_length = 0;
  1487. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1488. const uint32_t err_code = ble_gap_device_identities_set_req_enc(pp_id_keys,
  1489. pp_local_irks,
  1490. len,
  1491. &(p_buffer[1]), &buffer_length);
  1492. //@note: Should never fail.
  1493. APP_ERROR_CHECK(err_code);
  1494. //@note: Increment buffer length as internally managed packet type field must be included.
  1495. return ser_sd_transport_cmd_write(p_buffer,
  1496. (++buffer_length),
  1497. gap_device_identities_set_rsp_dec);
  1498. }
  1499. #if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
  1500. /**@brief Command response callback function for @ref sd_ble_gap_data_length_update BLE command.
  1501. *
  1502. * Callback for decoding the output parameters and the command response return code.
  1503. *
  1504. * @param[in] p_buffer Pointer to begin of command response buffer.
  1505. * @param[in] length Length of data in bytes.
  1506. *
  1507. * @return Decoded command response return code.
  1508. */
  1509. static uint32_t gap_data_length_update_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1510. {
  1511. uint32_t result_code = 0;
  1512. const uint32_t err_code = ble_gap_data_length_update_rsp_dec(p_buffer,
  1513. length,
  1514. (ble_gap_data_length_limitation_t *)mp_out_params[0],
  1515. &result_code);
  1516. //@note: Should never fail.
  1517. APP_ERROR_CHECK(err_code);
  1518. return result_code;
  1519. }
  1520. #ifndef _sd_ble_gap_data_length_update
  1521. #define _sd_ble_gap_data_length_update sd_ble_gap_data_length_update
  1522. #endif
  1523. uint32_t _sd_ble_gap_data_length_update(uint16_t conn_handle,
  1524. ble_gap_data_length_params_t const *p_dl_params,
  1525. ble_gap_data_length_limitation_t *p_dl_limitation)
  1526. {
  1527. uint8_t * p_buffer;
  1528. uint32_t buffer_length = 0;
  1529. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1530. mp_out_params[0] = p_dl_limitation;
  1531. const uint32_t err_code = ble_gap_data_length_update_req_enc(conn_handle, p_dl_params,p_dl_limitation,
  1532. &(p_buffer[1]), &buffer_length);
  1533. //@note: Should never fail.
  1534. APP_ERROR_CHECK(err_code);
  1535. //@note: Increment buffer length as internally managed packet type field must be included.
  1536. return ser_sd_transport_cmd_write(p_buffer,
  1537. (++buffer_length),
  1538. gap_data_length_update_rsp_dec);
  1539. }
  1540. #endif // NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
  1541. #if NRF_SD_BLE_API_VERSION >= 5
  1542. /**@brief Command response callback function for @ref sd_ble_gap_phy_update BLE command.
  1543. *
  1544. * Callback for decoding the output parameters and the command response return code.
  1545. *
  1546. * @param[in] p_buffer Pointer to begin of command response buffer.
  1547. * @param[in] length Length of data in bytes.
  1548. *
  1549. * @return Decoded command response return code.
  1550. */
  1551. static uint32_t gap_phy_update_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1552. {
  1553. uint32_t result_code = 0;
  1554. const uint32_t err_code = ble_gap_phy_update_rsp_dec(p_buffer,
  1555. length,
  1556. &result_code);
  1557. //@note: Should never fail.
  1558. APP_ERROR_CHECK(err_code);
  1559. return result_code;
  1560. }
  1561. #ifndef _sd_ble_gap_phy_update
  1562. #define _sd_ble_gap_phy_update sd_ble_gap_phy_update
  1563. #endif
  1564. uint32_t _sd_ble_gap_phy_update(uint16_t conn_handle,
  1565. ble_gap_phys_t const * const p_gap_phys)
  1566. {
  1567. uint8_t * p_buffer;
  1568. uint32_t buffer_length = 0;
  1569. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1570. const uint32_t err_code = ble_gap_phy_update_req_enc(conn_handle, p_gap_phys,
  1571. &(p_buffer[1]), &buffer_length);
  1572. //@note: Should never fail.
  1573. APP_ERROR_CHECK(err_code);
  1574. //@note: Increment buffer length as internally managed packet type field must be included.
  1575. return ser_sd_transport_cmd_write(p_buffer,
  1576. (++buffer_length),
  1577. gap_phy_update_rsp_dec);
  1578. }
  1579. #endif
  1580. #if NRF_SD_BLE_API_VERSION >= 6
  1581. /**@brief Command response callback function for @ref sd_ble_gap_adv_set_configure BLE command.
  1582. *
  1583. * Callback for decoding the output parameters and the command response return code.
  1584. *
  1585. * @param[in] p_buffer Pointer to begin of command response buffer.
  1586. * @param[in] length Length of data in bytes.
  1587. *
  1588. * @return Decoded command response return code.
  1589. */
  1590. static uint32_t gap_adv_set_configure_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1591. {
  1592. uint32_t result_code = 0;
  1593. uint32_t err_code = ble_gap_adv_set_configure_rsp_dec(p_buffer,
  1594. length,
  1595. (uint8_t *)mp_out_params[0],
  1596. &result_code);
  1597. if (result_code != NRF_SUCCESS)
  1598. {
  1599. app_ble_gap_adv_buf_addr_unregister(mp_out_params[1], false);
  1600. app_ble_gap_adv_buf_addr_unregister(mp_out_params[2], false);
  1601. }
  1602. //@note: Should never fail.
  1603. APP_ERROR_CHECK(err_code);
  1604. APP_ERROR_CHECK(err_code);
  1605. return result_code;
  1606. }
  1607. #ifndef _sd_ble_gap_adv_set_configure
  1608. #define _sd_ble_gap_adv_set_configure sd_ble_gap_adv_set_configure
  1609. #endif
  1610. uint32_t _sd_ble_gap_adv_set_configure(uint8_t *p_adv_handle,
  1611. ble_gap_adv_data_t const *p_adv_data,
  1612. ble_gap_adv_params_t const *p_adv_params)
  1613. {
  1614. uint8_t * p_buffer;
  1615. uint32_t buffer_length = 0;
  1616. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1617. mp_out_params[0] = p_adv_handle;
  1618. if (p_adv_handle)
  1619. {
  1620. mp_out_params[1] = p_adv_data->adv_data.p_data;
  1621. mp_out_params[2] = p_adv_data->scan_rsp_data.p_data;
  1622. }
  1623. else
  1624. {
  1625. mp_out_params[1] = NULL;
  1626. mp_out_params[2] = NULL;
  1627. }
  1628. const uint32_t err_code = ble_gap_adv_set_configure_req_enc(p_adv_handle, p_adv_data, p_adv_params,
  1629. &(p_buffer[1]), &buffer_length);
  1630. //@note: Should never fail.
  1631. APP_ERROR_CHECK(err_code);
  1632. //@note: Increment buffer length as internally managed packet type field must be included.
  1633. return ser_sd_transport_cmd_write(p_buffer,
  1634. (++buffer_length),
  1635. gap_adv_set_configure_rsp_dec);
  1636. }
  1637. #ifndef S112
  1638. /**@brief Command response callback function for @ref sd_ble_gap_qos_channel_survey_start BLE command.
  1639. *
  1640. * Callback for decoding the output parameters and the command response return code.
  1641. *
  1642. * @param[in] p_buffer Pointer to begin of command response buffer.
  1643. * @param[in] length Length of data in bytes.
  1644. *
  1645. * @return Decoded command response return code.
  1646. */
  1647. static uint32_t gap_qos_channel_survey_start_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1648. {
  1649. uint32_t result_code = 0;
  1650. uint32_t err_code = ble_gap_qos_channel_survey_start_rsp_dec(p_buffer,
  1651. length,
  1652. &result_code);
  1653. //@note: Should never fail.
  1654. APP_ERROR_CHECK(err_code);
  1655. return result_code;
  1656. }
  1657. #ifndef _sd_ble_gap_qos_channel_survey_start
  1658. #define _sd_ble_gap_qos_channel_survey_start sd_ble_gap_qos_channel_survey_start
  1659. #endif
  1660. uint32_t _sd_ble_gap_qos_channel_survey_start(uint32_t interval_us)
  1661. {
  1662. uint8_t * p_buffer;
  1663. uint32_t buffer_length = 0;
  1664. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1665. const uint32_t err_code = ble_gap_qos_channel_survey_start_req_enc(interval_us,
  1666. &(p_buffer[1]), &buffer_length);
  1667. //@note: Should never fail.
  1668. APP_ERROR_CHECK(err_code);
  1669. //@note: Increment buffer length as internally managed packet type field must be included.
  1670. return ser_sd_transport_cmd_write(p_buffer,
  1671. (++buffer_length),
  1672. gap_qos_channel_survey_start_rsp_dec);
  1673. }
  1674. /**@brief Command response callback function for @ref sd_ble_gap_qos_channel_survey_stop BLE command.
  1675. *
  1676. * Callback for decoding the output parameters and the command response return code.
  1677. *
  1678. * @param[in] p_buffer Pointer to begin of command response buffer.
  1679. * @param[in] length Length of data in bytes.
  1680. *
  1681. * @return Decoded command response return code.
  1682. */
  1683. static uint32_t gap_qos_channel_survey_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1684. {
  1685. uint32_t result_code = 0;
  1686. uint32_t err_code = ble_gap_qos_channel_survey_stop_rsp_dec(p_buffer,
  1687. length,
  1688. &result_code);
  1689. //@note: Should never fail.
  1690. APP_ERROR_CHECK(err_code);
  1691. return result_code;
  1692. }
  1693. #ifndef _sd_ble_gap_qos_channel_survey_stop
  1694. #define _sd_ble_gap_qos_channel_survey_stop sd_ble_gap_qos_channel_survey_stop
  1695. #endif
  1696. uint32_t _sd_ble_gap_qos_channel_survey_stop(void)
  1697. {
  1698. uint8_t * p_buffer;
  1699. uint32_t buffer_length = 0;
  1700. tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
  1701. const uint32_t err_code = ble_gap_qos_channel_survey_stop_req_enc(&(p_buffer[1]), &buffer_length);
  1702. //@note: Should never fail.
  1703. APP_ERROR_CHECK(err_code);
  1704. //@note: Increment buffer length as internally managed packet type field must be included.
  1705. return ser_sd_transport_cmd_write(p_buffer,
  1706. (++buffer_length),
  1707. gap_qos_channel_survey_stop_rsp_dec);
  1708. }
  1709. #endif //!S112
  1710. #endif