ble_gap_app.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /**
  2. * Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "ble_gap_app.h"
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include "ble_serialization.h"
  44. #include "ble_gap_struct_serialization.h"
  45. #include "ble_struct_serialization.h"
  46. #include "cond_field_serialization.h"
  47. #include "app_util.h"
  48. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
  49. uint32_t ble_gap_adv_data_set_req_enc(uint8_t const * const p_data,
  50. uint8_t dlen,
  51. uint8_t const * const p_sr_data,
  52. uint8_t srdlen,
  53. uint8_t * const p_buf,
  54. uint32_t * const p_buf_len)
  55. {
  56. SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_DATA_SET);
  57. SER_PUSH_len8data(p_data, dlen);
  58. SER_PUSH_len8data(p_sr_data, srdlen);
  59. SER_REQ_ENC_END;
  60. }
  61. uint32_t ble_gap_adv_data_set_rsp_dec(uint8_t const * const p_buf,
  62. uint32_t packet_len,
  63. uint32_t * const p_result_code)
  64. {
  65. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADV_DATA_SET);
  66. }
  67. #endif
  68. uint32_t ble_gap_adv_start_req_enc(
  69. #if NRF_SD_BLE_API_VERSION > 5
  70. uint8_t adv_handle,
  71. #else
  72. ble_gap_adv_params_t const * const p_adv_params,
  73. #endif
  74. #if NRF_SD_BLE_API_VERSION >= 4
  75. uint8_t conn_cfg_tag,
  76. #endif
  77. uint8_t * const p_buf,
  78. uint32_t * const p_buf_len)
  79. {
  80. SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_START);
  81. #if NRF_SD_BLE_API_VERSION > 5
  82. SER_PUSH_uint8(&adv_handle);
  83. #else
  84. SER_PUSH_COND(p_adv_params, ble_gap_adv_params_t_enc);
  85. #endif
  86. #if NRF_SD_BLE_API_VERSION >= 4
  87. SER_PUSH_uint8(&conn_cfg_tag);
  88. #endif
  89. SER_REQ_ENC_END;
  90. }
  91. uint32_t ble_gap_adv_start_rsp_dec(uint8_t const * const p_buf,
  92. uint32_t packet_len,
  93. uint32_t * const p_result_code)
  94. {
  95. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADV_START);
  96. }
  97. uint32_t ble_gap_adv_stop_req_enc(
  98. #if NRF_SD_BLE_API_VERSION > 5
  99. uint8_t adv_handle,
  100. #endif
  101. uint8_t * const p_buf,
  102. uint32_t * const p_buf_len)
  103. {
  104. SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_STOP);
  105. #if NRF_SD_BLE_API_VERSION > 5
  106. SER_PUSH_uint8(&adv_handle);
  107. #endif
  108. SER_REQ_ENC_END;
  109. }
  110. uint32_t ble_gap_adv_stop_rsp_dec(uint8_t const * const p_buf,
  111. uint32_t packet_len,
  112. uint32_t * const p_result_code)
  113. {
  114. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADV_STOP);
  115. }
  116. uint32_t ble_gap_appearance_get_req_enc(uint16_t const * const p_appearance,
  117. uint8_t * const p_buf,
  118. uint32_t * const p_buf_len)
  119. {
  120. SER_REQ_ENC_BEGIN(SD_BLE_GAP_APPEARANCE_GET);
  121. SER_PUSH_COND(p_appearance, NULL);
  122. SER_REQ_ENC_END;
  123. }
  124. uint32_t ble_gap_appearance_get_rsp_dec(uint8_t const * const p_buf,
  125. uint32_t packet_len,
  126. uint16_t * const p_appearance,
  127. uint32_t * const p_result_code)
  128. {
  129. SER_RSP_DEC_BEGIN(SD_BLE_GAP_APPEARANCE_GET);
  130. SER_PULL_COND(&p_appearance, uint16_t_dec);
  131. SER_RSP_DEC_END;
  132. }
  133. uint32_t ble_gap_appearance_set_req_enc(uint16_t appearance,
  134. uint8_t * const p_buf,
  135. uint32_t * const p_buf_len)
  136. {
  137. SER_REQ_ENC_BEGIN(SD_BLE_GAP_APPEARANCE_SET);
  138. SER_PUSH_uint16(&appearance);
  139. SER_REQ_ENC_END;
  140. }
  141. uint32_t ble_gap_appearance_set_rsp_dec(uint8_t const * const p_buf,
  142. uint32_t packet_len,
  143. uint32_t * const p_result_code)
  144. {
  145. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_APPEARANCE_SET);
  146. }
  147. uint32_t ble_gap_auth_key_reply_req_enc(uint16_t conn_handle,
  148. uint8_t key_type,
  149. uint8_t const * const p_key,
  150. uint8_t * const p_buf,
  151. uint32_t * const p_buf_len)
  152. {
  153. SER_REQ_ENC_BEGIN(SD_BLE_GAP_AUTH_KEY_REPLY);
  154. uint8_t key_len;
  155. switch (key_type)
  156. {
  157. case BLE_GAP_AUTH_KEY_TYPE_NONE:
  158. key_len = 0;
  159. break;
  160. case BLE_GAP_AUTH_KEY_TYPE_PASSKEY:
  161. key_len = 6;
  162. break;
  163. case BLE_GAP_AUTH_KEY_TYPE_OOB:
  164. key_len = 16;
  165. break;
  166. default:
  167. return NRF_ERROR_INVALID_PARAM;
  168. }
  169. SER_PUSH_uint16(&conn_handle);
  170. SER_PUSH_uint8(&key_type);
  171. SER_PUSH_buf(p_key, key_len);
  172. SER_REQ_ENC_END;
  173. }
  174. uint32_t ble_gap_auth_key_reply_rsp_dec(uint8_t const * const p_buf,
  175. uint32_t packet_len,
  176. uint32_t * const p_result_code)
  177. {
  178. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_AUTH_KEY_REPLY);
  179. }
  180. uint32_t ble_gap_authenticate_req_enc(uint16_t conn_handle,
  181. ble_gap_sec_params_t const * const p_sec_params,
  182. uint8_t * const p_buf,
  183. uint32_t * const p_buf_len)
  184. {
  185. SER_REQ_ENC_BEGIN(SD_BLE_GAP_AUTHENTICATE);
  186. SER_PUSH_uint16(&conn_handle);
  187. SER_PUSH_COND(p_sec_params, ble_gap_sec_params_t_enc);
  188. SER_REQ_ENC_END;
  189. }
  190. uint32_t ble_gap_authenticate_rsp_dec(uint8_t const * const p_buf,
  191. uint32_t packet_len,
  192. uint32_t * const p_result_code)
  193. {
  194. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_AUTHENTICATE);
  195. }
  196. uint32_t ble_gap_conn_param_update_req_enc(uint16_t conn_handle,
  197. ble_gap_conn_params_t const * const p_conn_params,
  198. uint8_t * const p_buf,
  199. uint32_t * const p_buf_len)
  200. {
  201. SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONN_PARAM_UPDATE);
  202. SER_PUSH_uint16(&conn_handle);
  203. SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc);
  204. SER_REQ_ENC_END;
  205. }
  206. uint32_t ble_gap_conn_param_update_rsp_dec(uint8_t const * const p_buf,
  207. uint32_t packet_len,
  208. uint32_t * const p_result_code)
  209. {
  210. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_CONN_PARAM_UPDATE);
  211. }
  212. uint32_t ble_gap_conn_sec_get_req_enc(uint16_t conn_handle,
  213. ble_gap_conn_sec_t const * const p_conn_sec,
  214. uint8_t * const p_buf,
  215. uint32_t * const p_buf_len)
  216. {
  217. SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONN_SEC_GET);
  218. SER_PUSH_uint16(&conn_handle);
  219. SER_PUSH_COND(p_conn_sec, NULL);
  220. SER_REQ_ENC_END;
  221. }
  222. uint32_t ble_gap_conn_sec_get_rsp_dec(uint8_t const * const p_buf,
  223. uint32_t packet_len,
  224. ble_gap_conn_sec_t * * const pp_conn_sec,
  225. uint32_t * const p_result_code)
  226. {
  227. SER_RSP_DEC_BEGIN(SD_BLE_GAP_CONN_SEC_GET);
  228. SER_PULL_COND(pp_conn_sec, ble_gap_conn_sec_t_dec);
  229. SER_RSP_DEC_END;
  230. }
  231. #ifndef S112
  232. uint32_t ble_gap_connect_req_enc(ble_gap_addr_t const * const p_peer_addr,
  233. ble_gap_scan_params_t const * const p_scan_params,
  234. ble_gap_conn_params_t const * const p_conn_params,
  235. #if NRF_SD_BLE_API_VERSION >= 4
  236. uint8_t conn_cfg_tag,
  237. #endif
  238. uint8_t * const p_buf,
  239. uint32_t * const p_buf_len)
  240. {
  241. SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONNECT);
  242. SER_PUSH_COND(p_peer_addr, ble_gap_addr_t_enc);
  243. SER_PUSH_COND(p_scan_params, ble_gap_scan_params_t_enc);
  244. SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc);
  245. #if NRF_SD_BLE_API_VERSION >= 4
  246. SER_PUSH_uint8(&conn_cfg_tag);
  247. #endif
  248. SER_REQ_ENC_END;
  249. }
  250. uint32_t ble_gap_connect_rsp_dec(uint8_t const * const p_buf,
  251. uint32_t packet_len,
  252. uint32_t * const p_result_code)
  253. {
  254. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_CONNECT);
  255. }
  256. uint32_t ble_gap_connect_cancel_req_enc(uint8_t * const p_buf,
  257. uint32_t * const p_buf_len)
  258. {
  259. SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONNECT_CANCEL);
  260. SER_REQ_ENC_END;
  261. }
  262. uint32_t ble_gap_connect_cancel_rsp_dec(uint8_t const * const p_buf,
  263. uint32_t packet_len,
  264. uint32_t * const p_result_code)
  265. {
  266. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_CONNECT_CANCEL);
  267. }
  268. #endif
  269. uint32_t ble_gap_device_name_get_req_enc(uint8_t const * const p_dev_name,
  270. uint16_t const * const p_len,
  271. uint8_t * const p_buf,
  272. uint32_t * const p_buf_len)
  273. {
  274. SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET);
  275. SER_PUSH_COND(p_len, uint16_t_enc);
  276. SER_PUSH_COND(p_dev_name, NULL);
  277. SER_REQ_ENC_END;
  278. }
  279. uint32_t ble_gap_device_name_get_rsp_dec(uint8_t const * const p_buf,
  280. uint32_t packet_len,
  281. uint8_t * const p_dev_name,
  282. uint16_t * const p_dev_name_len,
  283. uint32_t * const p_result_code)
  284. {
  285. SER_RSP_DEC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET);
  286. uint16_t cpy_len = 0xffff;
  287. SER_PULL_COND(&p_dev_name_len, uint16_t_dec);
  288. SER_PULL_len16data((uint8_t **)&p_dev_name, &cpy_len);
  289. SER_RSP_DEC_END;
  290. }
  291. uint32_t ble_gap_device_name_set_req_enc(ble_gap_conn_sec_mode_t const * const p_write_perm,
  292. uint8_t const * const p_dev_name,
  293. uint16_t len,
  294. uint8_t * const p_buf,
  295. uint32_t * const p_buf_len)
  296. {
  297. SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_NAME_SET);
  298. SER_ERROR_CHECK(len <= BLE_GAP_DEVNAME_MAX_LEN, NRF_ERROR_INVALID_PARAM);
  299. SER_PUSH_COND(p_write_perm, ble_gap_conn_sec_mode_t_enc);
  300. SER_PUSH_len16data(p_dev_name, len);
  301. SER_REQ_ENC_END;
  302. }
  303. uint32_t ble_gap_device_name_set_rsp_dec(uint8_t const * const p_buf,
  304. uint32_t packet_len,
  305. uint32_t * const p_result_code)
  306. {
  307. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_DEVICE_NAME_SET);
  308. }
  309. uint32_t ble_gap_disconnect_req_enc(uint16_t conn_handle,
  310. uint8_t hci_status_code,
  311. uint8_t * const p_buf,
  312. uint32_t * const p_buf_len)
  313. {
  314. SER_REQ_ENC_BEGIN(SD_BLE_GAP_DISCONNECT);
  315. SER_PUSH_uint16(&conn_handle);
  316. SER_PUSH_uint8(&hci_status_code);
  317. SER_REQ_ENC_END;
  318. }
  319. uint32_t ble_gap_disconnect_rsp_dec(uint8_t const * const p_buf,
  320. uint32_t packet_len,
  321. uint32_t * const p_result_code)
  322. {
  323. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_DISCONNECT);
  324. }
  325. #ifndef S112
  326. uint32_t ble_gap_encrypt_req_enc(uint16_t conn_handle,
  327. ble_gap_master_id_t const * const p_master_id,
  328. ble_gap_enc_info_t const * const p_enc_info,
  329. uint8_t * const p_buf,
  330. uint32_t * const p_buf_len)
  331. {
  332. SER_REQ_ENC_BEGIN(SD_BLE_GAP_ENCRYPT);
  333. SER_PUSH_uint16(&conn_handle);
  334. SER_PUSH_COND(p_master_id, ble_gap_master_id_t_enc);
  335. SER_PUSH_COND(p_enc_info, ble_gap_enc_info_t_enc);
  336. SER_REQ_ENC_END;
  337. }
  338. uint32_t ble_gap_encrypt_rsp_dec(uint8_t const * const p_buf,
  339. uint32_t packet_len,
  340. uint32_t * const p_result_code)
  341. {
  342. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ENCRYPT);
  343. }
  344. #endif
  345. uint32_t ble_gap_keypress_notify_req_enc(uint16_t conn_handle,
  346. uint8_t kp_not,
  347. uint8_t * const p_buf,
  348. uint32_t * const p_buf_len)
  349. {
  350. SER_REQ_ENC_BEGIN(SD_BLE_GAP_KEYPRESS_NOTIFY);
  351. SER_PUSH_uint16(&conn_handle);
  352. SER_PUSH_uint8(&kp_not);
  353. SER_REQ_ENC_END;
  354. }
  355. uint32_t ble_gap_keypress_notify_rsp_dec(uint8_t const * const p_buf,
  356. uint32_t packet_len,
  357. uint32_t * const p_result_code)
  358. {
  359. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_KEYPRESS_NOTIFY);
  360. }
  361. uint32_t ble_gap_lesc_dhkey_reply_req_enc(uint16_t conn_handle,
  362. ble_gap_lesc_dhkey_t const *p_dhkey,
  363. uint8_t * const p_buf,
  364. uint32_t * const p_buf_len)
  365. {
  366. SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_DHKEY_REPLY);
  367. SER_PUSH_uint16(&conn_handle);
  368. SER_PUSH_COND(p_dhkey, ble_gap_lesc_dhkey_t_enc);
  369. SER_REQ_ENC_END;
  370. }
  371. uint32_t ble_gap_lesc_dhkey_reply_rsp_dec(uint8_t const * const p_buf,
  372. uint32_t packet_len,
  373. uint32_t * const p_result_code)
  374. {
  375. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_LESC_DHKEY_REPLY);
  376. }
  377. uint32_t ble_gap_lesc_oob_data_get_req_enc(uint16_t conn_handle,
  378. ble_gap_lesc_p256_pk_t const *p_pk_own,
  379. ble_gap_lesc_oob_data_t *p_oobd_own,
  380. uint8_t * const p_buf,
  381. uint32_t * const p_buf_len)
  382. {
  383. SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET);
  384. SER_PUSH_uint16(&conn_handle);
  385. SER_PUSH_COND(p_pk_own, ble_gap_lesc_p256_pk_t_enc);
  386. SER_PUSH_COND(p_oobd_own, NULL);
  387. SER_REQ_ENC_END;
  388. }
  389. uint32_t ble_gap_lesc_oob_data_get_rsp_dec(uint8_t const * const p_buf,
  390. uint32_t packet_len,
  391. ble_gap_lesc_oob_data_t * *pp_oobd_own,
  392. uint32_t * const p_result_code)
  393. {
  394. SER_RSP_DEC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET);
  395. SER_PULL_COND(pp_oobd_own, ble_gap_lesc_oob_data_t_dec);
  396. SER_RSP_DEC_END;
  397. }
  398. uint32_t ble_gap_lesc_oob_data_set_req_enc(uint16_t conn_handle,
  399. ble_gap_lesc_oob_data_t const *p_oobd_own,
  400. ble_gap_lesc_oob_data_t const *p_oobd_peer,
  401. uint8_t * const p_buf,
  402. uint32_t * const p_buf_len)
  403. {
  404. SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_SET);
  405. SER_PUSH_uint16(&conn_handle);
  406. SER_PUSH_COND(p_oobd_own, ble_gap_lesc_oob_data_t_enc);
  407. SER_PUSH_COND(p_oobd_peer, ble_gap_lesc_oob_data_t_enc);
  408. SER_REQ_ENC_END;
  409. }
  410. uint32_t ble_gap_lesc_oob_data_set_rsp_dec(uint8_t const * const p_buf,
  411. uint32_t packet_len,
  412. uint32_t * const p_result_code)
  413. {
  414. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_LESC_OOB_DATA_SET);
  415. }
  416. uint32_t ble_gap_ppcp_get_req_enc(ble_gap_conn_params_t const * const p_conn_params,
  417. uint8_t * const p_buf,
  418. uint32_t * const p_buf_len)
  419. {
  420. SER_REQ_ENC_BEGIN(SD_BLE_GAP_PPCP_GET);
  421. SER_PUSH_COND(p_conn_params, NULL);
  422. SER_REQ_ENC_END;
  423. }
  424. uint32_t ble_gap_ppcp_get_rsp_dec(uint8_t const * const p_buf,
  425. uint32_t packet_len,
  426. ble_gap_conn_params_t * const p_conn_params,
  427. uint32_t * const p_result_code)
  428. {
  429. SER_RSP_DEC_BEGIN(SD_BLE_GAP_PPCP_GET);
  430. SER_PULL_COND(&p_conn_params, ble_gap_conn_params_t_dec);
  431. SER_RSP_DEC_END;
  432. }
  433. uint32_t ble_gap_ppcp_set_req_enc(ble_gap_conn_params_t const * const p_conn_params,
  434. uint8_t * const p_buf,
  435. uint32_t * const p_buf_len)
  436. {
  437. SER_REQ_ENC_BEGIN(SD_BLE_GAP_PPCP_SET);
  438. SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc);
  439. SER_REQ_ENC_END;
  440. }
  441. uint32_t ble_gap_ppcp_set_rsp_dec(uint8_t const * const p_buf,
  442. uint32_t packet_len,
  443. uint32_t * const p_result_code)
  444. {
  445. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_PPCP_SET);
  446. }
  447. uint32_t ble_gap_rssi_get_req_enc(uint16_t conn_handle,
  448. int8_t const * const p_rssi,
  449. #if NRF_SD_BLE_API_VERSION > 5
  450. uint8_t const * const p_ch_index,
  451. #endif
  452. uint8_t * const p_buf,
  453. uint32_t * const p_buf_len)
  454. {
  455. SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_GET);
  456. SER_PUSH_uint16(&conn_handle);
  457. SER_PUSH_COND(p_rssi, NULL);
  458. #if NRF_SD_BLE_API_VERSION > 5
  459. SER_PUSH_COND(p_ch_index, NULL);
  460. #endif
  461. SER_REQ_ENC_END;
  462. }
  463. uint32_t ble_gap_rssi_get_rsp_dec(uint8_t const * const p_buf,
  464. uint32_t packet_len,
  465. int8_t * const p_rssi,
  466. #if NRF_SD_BLE_API_VERSION > 5
  467. uint8_t * const p_ch_index,
  468. #endif
  469. uint32_t * const p_result_code)
  470. {
  471. SER_RSP_DEC_BEGIN(SD_BLE_GAP_RSSI_GET);
  472. SER_PULL_COND(&p_rssi, uint8_t_dec);
  473. #if NRF_SD_BLE_API_VERSION > 5
  474. SER_PULL_COND(&p_ch_index, uint8_t_dec);
  475. #endif
  476. SER_RSP_DEC_END;
  477. }
  478. uint32_t ble_gap_rssi_start_req_enc(uint16_t conn_handle,
  479. uint8_t threshold_dbm,
  480. uint8_t skip_count,
  481. uint8_t * const p_buf,
  482. uint32_t * const p_buf_len)
  483. {
  484. SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_START);
  485. SER_PUSH_uint16(&conn_handle);
  486. SER_PUSH_uint8(&threshold_dbm);
  487. SER_PUSH_uint8(&skip_count);
  488. SER_REQ_ENC_END;
  489. }
  490. uint32_t ble_gap_rssi_start_rsp_dec(uint8_t const * const p_buf,
  491. uint32_t packet_len,
  492. uint32_t * const p_result_code)
  493. {
  494. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_RSSI_START);
  495. }
  496. uint32_t ble_gap_rssi_stop_req_enc(uint16_t conn_handle,
  497. uint8_t * const p_buf,
  498. uint32_t * const p_buf_len)
  499. {
  500. SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_STOP);
  501. SER_PUSH_uint16(&conn_handle);
  502. SER_REQ_ENC_END;
  503. }
  504. uint32_t ble_gap_rssi_stop_rsp_dec(uint8_t const * const p_buf,
  505. uint32_t packet_len,
  506. uint32_t * const p_result_code)
  507. {
  508. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_RSSI_STOP);
  509. }
  510. #ifndef S112
  511. uint32_t ble_gap_scan_start_req_enc(ble_gap_scan_params_t const * p_scan_params,
  512. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  513. ble_data_t const * p_adv_report_buffer,
  514. #endif
  515. uint8_t * const p_buf,
  516. uint32_t * const p_buf_len)
  517. {
  518. SER_REQ_ENC_BEGIN(SD_BLE_GAP_SCAN_START);
  519. SER_PUSH_COND(p_scan_params, ble_gap_scan_params_t_enc);
  520. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  521. SER_PUSH_COND(p_adv_report_buffer, ble_data_t_enc);
  522. #endif
  523. SER_REQ_ENC_END;
  524. }
  525. uint32_t ble_gap_scan_start_rsp_dec(uint8_t const * const p_buf,
  526. uint32_t packet_len,
  527. uint32_t * const p_result_code)
  528. {
  529. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_SCAN_START);
  530. }
  531. uint32_t ble_gap_scan_stop_req_enc(uint8_t * const p_buf,
  532. uint32_t * const p_buf_len)
  533. {
  534. SER_REQ_ENC_BEGIN(SD_BLE_GAP_SCAN_STOP);
  535. SER_REQ_ENC_END;
  536. }
  537. uint32_t ble_gap_scan_stop_rsp_dec(uint8_t const * const p_buf,
  538. uint32_t packet_len,
  539. uint32_t * const p_result_code)
  540. {
  541. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_SCAN_STOP);
  542. }
  543. #endif
  544. uint32_t ble_gap_sec_info_reply_req_enc(uint16_t conn_handle,
  545. ble_gap_enc_info_t const * p_enc_info,
  546. ble_gap_irk_t const * p_id_info,
  547. ble_gap_sign_info_t const * p_sign_info,
  548. uint8_t * const p_buf,
  549. uint32_t * const p_buf_len)
  550. {
  551. SER_REQ_ENC_BEGIN(SD_BLE_GAP_SEC_INFO_REPLY);
  552. SER_PUSH_uint16(&conn_handle);
  553. SER_PUSH_COND(p_enc_info, ble_gap_enc_info_t_enc);
  554. SER_PUSH_COND(p_id_info, ble_gap_irk_t_enc);
  555. SER_PUSH_COND(p_sign_info, ble_gap_sign_info_t_enc);
  556. SER_REQ_ENC_END;
  557. }
  558. uint32_t ble_gap_sec_info_reply_rsp_dec(uint8_t const * const p_buf,
  559. uint32_t packet_len,
  560. uint32_t * const p_result_code)
  561. {
  562. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_SEC_INFO_REPLY);
  563. }
  564. uint32_t ble_gap_sec_params_reply_req_enc(uint16_t conn_handle,
  565. uint8_t sec_status,
  566. ble_gap_sec_params_t const * const p_sec_params,
  567. ble_gap_sec_keyset_t const * const p_sec_keyset,
  568. uint8_t * const p_buf,
  569. uint32_t * const p_buf_len)
  570. {
  571. SER_REQ_ENC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY);
  572. SER_PUSH_uint16(&conn_handle);
  573. SER_PUSH_uint8(&sec_status);
  574. SER_PUSH_COND(p_sec_params, ble_gap_sec_params_t_enc);
  575. SER_PUSH_COND(p_sec_keyset, ble_gap_sec_keyset_t_enc);
  576. SER_REQ_ENC_END;
  577. }
  578. uint32_t ble_gap_sec_params_reply_rsp_dec(uint8_t const * const p_buf,
  579. uint32_t packet_len,
  580. ble_gap_sec_keyset_t const * const p_sec_keyset,
  581. uint32_t * const p_result_code)
  582. {
  583. SER_RSP_DEC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY);
  584. SER_PULL_COND(&p_sec_keyset, ble_gap_sec_keyset_t_dec);
  585. SER_RSP_DEC_END;
  586. }
  587. uint32_t ble_gap_tx_power_set_req_enc(
  588. #if NRF_SD_BLE_API_VERSION > 5
  589. uint8_t role, uint16_t handle,
  590. #endif
  591. int8_t tx_power,
  592. uint8_t * const p_buf,
  593. uint32_t * const p_buf_len)
  594. {
  595. SER_REQ_ENC_BEGIN(SD_BLE_GAP_TX_POWER_SET);
  596. #if NRF_SD_BLE_API_VERSION > 5
  597. SER_PUSH_uint8(&role);
  598. SER_PUSH_uint16(&handle);
  599. #endif
  600. SER_PUSH_int8(&tx_power);
  601. SER_REQ_ENC_END;
  602. }
  603. uint32_t ble_gap_tx_power_set_rsp_dec(uint8_t const * const p_buf,
  604. uint32_t packet_len,
  605. uint32_t * const p_result_code)
  606. {
  607. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_TX_POWER_SET);
  608. }
  609. uint32_t ble_gap_addr_get_req_enc(ble_gap_addr_t const * const p_address,
  610. uint8_t * const p_buf,
  611. uint32_t * const p_buf_len)
  612. {
  613. SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADDR_GET);
  614. SER_PUSH_COND(p_address, NULL);
  615. SER_REQ_ENC_END;
  616. }
  617. uint32_t ble_gap_addr_get_rsp_dec(uint8_t const * const p_buf,
  618. uint32_t packet_len,
  619. ble_gap_addr_t * const p_address,
  620. uint32_t * const p_result_code)
  621. {
  622. SER_RSP_DEC_BEGIN(SD_BLE_GAP_ADDR_GET);
  623. SER_PULL_FIELD(p_address, ble_gap_addr_t_dec);
  624. SER_RSP_DEC_END;
  625. }
  626. uint32_t ble_gap_addr_set_req_enc(ble_gap_addr_t const * const p_addr,
  627. uint8_t * const p_buf,
  628. uint32_t * const p_buf_len)
  629. {
  630. SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADDR_SET);
  631. SER_PUSH_COND(p_addr, ble_gap_addr_t_enc);
  632. SER_REQ_ENC_END;
  633. }
  634. uint32_t ble_gap_addr_set_rsp_dec(uint8_t const * const p_buf,
  635. uint32_t packet_len,
  636. uint32_t * const p_result_code)
  637. {
  638. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADDR_SET);
  639. }
  640. uint32_t ble_gap_privacy_set_req_enc(ble_gap_privacy_params_t const * p_privacy_params,
  641. uint8_t * const p_buf,
  642. uint32_t * const p_buf_len)
  643. {
  644. SER_REQ_ENC_BEGIN(SD_BLE_GAP_PRIVACY_SET);
  645. SER_PUSH_COND(p_privacy_params, ble_gap_privacy_params_t_enc);
  646. SER_REQ_ENC_END;
  647. }
  648. uint32_t ble_gap_privacy_set_rsp_dec(uint8_t const * const p_buf,
  649. uint32_t packet_len,
  650. uint32_t * const p_result_code)
  651. {
  652. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_PRIVACY_SET);
  653. }
  654. uint32_t ble_gap_privacy_get_req_enc(ble_gap_privacy_params_t const * const p_privacy_params,
  655. uint8_t * const p_buf,
  656. uint32_t * const p_buf_len)
  657. {
  658. SER_REQ_ENC_BEGIN(SD_BLE_GAP_PRIVACY_GET);
  659. SER_PUSH_COND(p_privacy_params, ble_gap_privacy_params_t_enc);
  660. SER_REQ_ENC_END;
  661. }
  662. uint32_t ble_gap_privacy_get_rsp_dec(uint8_t const * const p_buf,
  663. uint32_t packet_len,
  664. ble_gap_privacy_params_t const * const p_privacy_params,
  665. uint32_t * const p_result_code)
  666. {
  667. SER_RSP_DEC_BEGIN(SD_BLE_GAP_PRIVACY_GET);
  668. SER_PULL_COND((void **)&p_privacy_params, ble_gap_privacy_params_t_dec);
  669. SER_RSP_DEC_END;
  670. }
  671. uint32_t ble_gap_whitelist_set_req_enc(ble_gap_addr_t const * const * const pp_wl_addrs,
  672. uint8_t const len,
  673. uint8_t * const p_buf,
  674. uint32_t * const p_buf_len)
  675. {
  676. SER_REQ_ENC_BEGIN(SD_BLE_GAP_WHITELIST_SET);
  677. uint8_t presence;
  678. SER_PUSH_uint8(&len);
  679. if (pp_wl_addrs)
  680. {
  681. presence = SER_FIELD_PRESENT;
  682. SER_PUSH_uint8(&presence);
  683. for (uint32_t i = 0; i < len; ++i)
  684. {
  685. SER_PUSH_COND(pp_wl_addrs[i], ble_gap_addr_t_enc);
  686. }
  687. }
  688. else
  689. {
  690. presence = SER_FIELD_NOT_PRESENT;
  691. SER_PUSH_uint8(&presence);
  692. }
  693. SER_REQ_ENC_END;
  694. }
  695. uint32_t ble_gap_whitelist_set_rsp_dec(uint8_t const * const p_buf,
  696. uint32_t packet_len,
  697. uint32_t * const p_result_code)
  698. {
  699. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_WHITELIST_SET);
  700. }
  701. uint32_t ble_gap_device_identities_set_req_enc(ble_gap_id_key_t const * const * const pp_id_keys,
  702. ble_gap_irk_t const * const * const pp_local_irks,
  703. uint8_t const len,
  704. uint8_t * const p_buf,
  705. uint32_t * const p_buf_len)
  706. {
  707. SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_IDENTITIES_SET);
  708. uint8_t presence;
  709. SER_PUSH_uint8(&len);
  710. if (pp_id_keys)
  711. {
  712. presence = SER_FIELD_PRESENT;
  713. SER_PUSH_uint8(&presence);
  714. for (uint32_t i = 0; i < len; ++i)
  715. {
  716. SER_PUSH_COND(pp_id_keys[i], ble_gap_id_key_t_enc);
  717. }
  718. }
  719. else
  720. {
  721. presence = SER_FIELD_NOT_PRESENT;
  722. SER_PUSH_uint8(&presence);
  723. }
  724. if (pp_local_irks)
  725. {
  726. presence = SER_FIELD_PRESENT;
  727. SER_PUSH_uint8(&presence);
  728. for (uint32_t i = 0; i < len; ++i)
  729. {
  730. SER_PUSH_COND(pp_local_irks[i], ble_gap_irk_t_enc);
  731. }
  732. }
  733. else
  734. {
  735. presence = SER_FIELD_NOT_PRESENT;
  736. SER_PUSH_uint8(&presence);
  737. }
  738. SER_REQ_ENC_END;
  739. }
  740. uint32_t ble_gap_device_identities_set_rsp_dec(uint8_t const * const p_buf,
  741. uint32_t packet_len,
  742. uint32_t * const p_result_code)
  743. {
  744. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_DEVICE_IDENTITIES_SET);
  745. }
  746. #if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
  747. uint32_t ble_gap_data_length_update_req_enc(uint16_t conn_handle,
  748. ble_gap_data_length_params_t const * p_dl_params,
  749. ble_gap_data_length_limitation_t * p_dl_limitation,
  750. uint8_t * const p_buf,
  751. uint32_t * const p_buf_len)
  752. {
  753. SER_REQ_ENC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE);
  754. SER_PUSH_uint16(&conn_handle);
  755. SER_PUSH_COND(p_dl_params, ble_gap_data_length_params_t_enc);
  756. SER_PUSH_COND(p_dl_limitation, NULL);
  757. SER_REQ_ENC_END;
  758. }
  759. uint32_t ble_gap_data_length_update_rsp_dec(uint8_t const * const p_buf,
  760. uint32_t packet_len,
  761. ble_gap_data_length_limitation_t * p_dl_limitation,
  762. uint32_t * const p_result_code)
  763. {
  764. SER_RSP_DEC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE);
  765. SER_PULL_COND((void **)&p_dl_limitation, ble_gap_data_length_limitation_t_dec);
  766. SER_RSP_DEC_END;
  767. }
  768. #endif
  769. #if NRF_SD_BLE_API_VERSION >= 5
  770. uint32_t ble_gap_phy_update_req_enc(uint16_t conn_handle,
  771. ble_gap_phys_t const * p_gap_phys,
  772. uint8_t * const p_buf,
  773. uint32_t * const p_buf_len)
  774. {
  775. SER_REQ_ENC_BEGIN(SD_BLE_GAP_PHY_UPDATE);
  776. SER_PUSH_uint16(&conn_handle);
  777. SER_PUSH_COND(p_gap_phys, ble_gap_phys_t_enc);
  778. SER_REQ_ENC_END;
  779. }
  780. uint32_t ble_gap_phy_update_rsp_dec(uint8_t const * const p_buf,
  781. uint32_t packet_len,
  782. uint32_t * const p_result_code)
  783. {
  784. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_PHY_UPDATE);
  785. }
  786. #endif
  787. #if NRF_SD_BLE_API_VERSION > 5
  788. uint32_t ble_gap_adv_set_configure_req_enc(uint8_t * p_adv_handle,
  789. ble_gap_adv_data_t const * p_adv_data,
  790. ble_gap_adv_params_t const *p_adv_params,
  791. uint8_t * const p_buf,
  792. uint32_t * const p_buf_len)
  793. {
  794. SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE);
  795. SER_PUSH_COND(p_adv_handle, uint8_t_enc);
  796. SER_PUSH_COND(p_adv_data, ble_gap_adv_data_t_enc);
  797. SER_PUSH_COND(p_adv_params, ble_gap_adv_params_t_enc);
  798. SER_REQ_ENC_END;
  799. }
  800. uint32_t ble_gap_adv_set_configure_rsp_dec(uint8_t const * const p_buf,
  801. uint32_t packet_len,
  802. uint8_t * p_adv_handle,
  803. uint32_t * const p_result_code)
  804. {
  805. SER_RSP_DEC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE);
  806. SER_PULL_COND((void **)&p_adv_handle, uint8_t_dec);
  807. SER_RSP_DEC_END;
  808. }
  809. #ifndef S112
  810. uint32_t ble_gap_qos_channel_survey_start_req_enc(uint32_t interval_us,
  811. uint8_t * const p_buf,
  812. uint32_t * const p_buf_len)
  813. {
  814. SER_REQ_ENC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_START);
  815. SER_PUSH_uint32(&interval_us);
  816. SER_REQ_ENC_END;
  817. }
  818. uint32_t ble_gap_qos_channel_survey_start_rsp_dec(uint8_t const * const p_buf,
  819. uint32_t packet_len,
  820. uint32_t * const p_result_code)
  821. {
  822. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_QOS_CHANNEL_SURVEY_START);
  823. }
  824. uint32_t ble_gap_qos_channel_survey_stop_req_enc(uint8_t * const p_buf,
  825. uint32_t * const p_buf_len)
  826. {
  827. SER_REQ_ENC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP);
  828. SER_REQ_ENC_END;
  829. }
  830. uint32_t ble_gap_qos_channel_survey_stop_rsp_dec(uint8_t const * const p_buf,
  831. uint32_t packet_len,
  832. uint32_t * const p_result_code)
  833. {
  834. SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP);
  835. }
  836. #endif //!S112
  837. #endif