ble_gap_struct_serialization.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743
  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_struct_serialization.h"
  41. #include "ble_struct_serialization.h"
  42. #include "ble_serialization.h"
  43. #include "cond_field_serialization.h"
  44. #include "app_util.h"
  45. #include "string.h"
  46. #include "ble_gatts.h"
  47. #ifndef S112
  48. uint32_t ble_gap_evt_adv_report_t_enc(void const * const p_void_struct,
  49. uint8_t * const p_buf,
  50. uint32_t buf_len,
  51. uint32_t * const p_index)
  52. {
  53. SER_STRUCT_ENC_BEGIN(ble_gap_evt_adv_report_t);
  54. #if NRF_SD_BLE_API_VERSION > 5
  55. SER_PUSH_FIELD(&p_struct->type, ble_gap_adv_report_type_t_enc);
  56. SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc);
  57. SER_PUSH_FIELD(&p_struct->direct_addr, ble_gap_addr_t_enc);
  58. SER_PUSH_uint8(&p_struct->primary_phy);
  59. SER_PUSH_uint8(&p_struct->secondary_phy);
  60. SER_PUSH_int8(&p_struct->tx_power);
  61. SER_PUSH_int8(&p_struct->rssi);
  62. SER_PUSH_uint8(&p_struct->ch_index);
  63. SER_PUSH_uint8(&p_struct->set_id);
  64. uint16_t temp = p_struct->data_id;
  65. SER_PUSH_uint16(&temp);
  66. SER_PUSH_FIELD(&p_struct->data, ble_data_t_enc);
  67. SER_PUSH_FIELD(&p_struct->aux_pointer, ble_gap_aux_pointer_t_enc);
  68. #else
  69. uint8_t ser_data = (p_struct->scan_rsp & 0x01)
  70. | ((p_struct->type & 0x03) << 1);
  71. uint8_t data_len = (p_struct->dlen & 0x1F);
  72. SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc);
  73. SER_PUSH_FIELD(&p_struct->direct_addr, ble_gap_addr_t_enc);
  74. SER_PUSH_int8(&p_struct->rssi);
  75. SER_PUSH_uint8(&ser_data);
  76. SER_PUSH_len8data(p_struct->data, data_len);
  77. #endif
  78. SER_STRUCT_ENC_END;
  79. }
  80. uint32_t ble_gap_evt_adv_report_t_dec(uint8_t const * const p_buf,
  81. uint32_t buf_len,
  82. uint32_t * const p_index,
  83. void * const p_void_struct)
  84. {
  85. SER_STRUCT_DEC_BEGIN(ble_gap_evt_adv_report_t);
  86. #if NRF_SD_BLE_API_VERSION > 5
  87. SER_PULL_FIELD(&p_struct->type, ble_gap_adv_report_type_t_dec);
  88. SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec);
  89. SER_PULL_FIELD(&p_struct->direct_addr, ble_gap_addr_t_dec);
  90. SER_PULL_uint8(&p_struct->primary_phy);
  91. SER_PULL_uint8(&p_struct->secondary_phy);
  92. SER_PULL_int8(&p_struct->tx_power);
  93. SER_PULL_int8(&p_struct->rssi);
  94. SER_PULL_uint8(&p_struct->ch_index);
  95. SER_PULL_uint8(&p_struct->set_id);
  96. uint16_t temp;
  97. SER_PULL_uint16(&temp);
  98. p_struct->data_id = temp & 0x0FFF;
  99. SER_PULL_FIELD(&p_struct->data, ble_data_t_dec);
  100. SER_PULL_FIELD(&p_struct->aux_pointer, ble_gap_aux_pointer_t_dec);
  101. #else
  102. uint8_t ser_data;
  103. uint8_t data_len = BLE_GAP_ADV_MAX_SIZE;
  104. uint8_t * p_field_data = p_struct->data;
  105. SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec);
  106. SER_PULL_FIELD(&p_struct->direct_addr, ble_gap_addr_t_dec);
  107. SER_PULL_int8(&p_struct->rssi);
  108. SER_PULL_uint8(&ser_data);
  109. SER_PULL_len8data(&p_field_data, &data_len);
  110. p_struct->scan_rsp = ser_data & 0x01;
  111. p_struct->type = (ser_data >> 1) & 0x03;
  112. p_struct->dlen = data_len;
  113. #endif
  114. SER_STRUCT_DEC_END;
  115. }
  116. #endif
  117. uint32_t ble_gap_irk_t_enc(void const * const p_void_struct,
  118. uint8_t * const p_buf,
  119. uint32_t buf_len,
  120. uint32_t * const p_index)
  121. {
  122. SER_STRUCT_ENC_BEGIN(ble_gap_irk_t);
  123. SER_PUSH_uint8array(p_struct->irk, BLE_GAP_SEC_KEY_LEN);
  124. SER_STRUCT_ENC_END;
  125. }
  126. uint32_t ble_gap_irk_t_dec(uint8_t const * const p_buf,
  127. uint32_t buf_len,
  128. uint32_t * const p_index,
  129. void * const p_void_struct)
  130. {
  131. SER_STRUCT_DEC_BEGIN(ble_gap_irk_t);
  132. SER_PULL_uint8array(p_struct->irk, BLE_GAP_SEC_KEY_LEN);
  133. SER_STRUCT_DEC_END;
  134. }
  135. uint32_t ble_gap_addr_t_enc(void const * const p_void_struct,
  136. uint8_t * const p_buf,
  137. uint32_t buf_len,
  138. uint32_t * const p_index)
  139. {
  140. SER_STRUCT_ENC_BEGIN(ble_gap_addr_t);
  141. uint8_t ser_data = (p_struct->addr_id_peer & 0x01)
  142. | ((p_struct->addr_type & 0x7F) << 1);
  143. SER_PUSH_uint8(&ser_data);
  144. SER_PUSH_uint8array(p_struct->addr, BLE_GAP_ADDR_LEN);
  145. SER_STRUCT_ENC_END;
  146. }
  147. uint32_t ble_gap_addr_t_dec(uint8_t const * const p_buf,
  148. uint32_t buf_len,
  149. uint32_t * const p_index,
  150. void * const p_void_struct)
  151. {
  152. SER_STRUCT_DEC_BEGIN(ble_gap_addr_t);
  153. uint8_t ser_data;
  154. SER_PULL_uint8(&ser_data);
  155. SER_PULL_uint8array(p_struct->addr, BLE_GAP_ADDR_LEN);
  156. p_struct->addr_id_peer = ser_data & 0x01;
  157. p_struct->addr_type = (ser_data >> 1) & 0x7F;
  158. SER_STRUCT_DEC_END;
  159. }
  160. uint32_t ble_gap_sec_levels_t_enc(void const * const p_void_struct,
  161. uint8_t * const p_buf,
  162. uint32_t buf_len,
  163. uint32_t * const p_index)
  164. {
  165. SER_STRUCT_ENC_BEGIN(ble_gap_sec_levels_t);
  166. uint8_t sec_levels_serialized = (p_struct->lv1 << 0) | (p_struct->lv2 << 1)
  167. | (p_struct->lv3 << 2) | (p_struct->lv4 << 3);
  168. SER_PUSH_uint8(&sec_levels_serialized);
  169. SER_STRUCT_ENC_END;
  170. }
  171. uint32_t ble_gap_sec_levels_t_dec(uint8_t const * const p_buf,
  172. uint32_t buf_len,
  173. uint32_t * const p_index,
  174. void * const p_void_struct)
  175. {
  176. SER_STRUCT_DEC_BEGIN(ble_gap_sec_levels_t);
  177. uint32_t sec_levels_serialized;
  178. SER_PULL_uint8(&sec_levels_serialized);
  179. p_struct->lv1 = sec_levels_serialized & 0x01;
  180. p_struct->lv2 = (sec_levels_serialized >> 1) & 0x01;
  181. p_struct->lv3 = (sec_levels_serialized >> 2) & 0x01;
  182. p_struct->lv4 = (sec_levels_serialized >> 3) & 0x01;
  183. SER_STRUCT_DEC_END;
  184. }
  185. uint32_t ble_gap_sec_keys_t_enc(void const * const p_void_struct,
  186. uint8_t * const p_buf,
  187. uint32_t buf_len,
  188. uint32_t * const p_index)
  189. {
  190. SER_STRUCT_ENC_BEGIN(ble_gap_sec_keys_t);
  191. SER_PUSH_COND(p_struct->p_enc_key, ble_gap_enc_key_t_enc);
  192. SER_PUSH_COND(p_struct->p_id_key, ble_gap_id_key_t_enc);
  193. SER_PUSH_COND(p_struct->p_sign_key, ble_gap_sign_info_t_enc);
  194. SER_PUSH_COND(p_struct->p_pk, ble_gap_lesc_p256_pk_t_enc);
  195. SER_STRUCT_ENC_END;
  196. }
  197. uint32_t ble_gap_sec_keys_t_dec(uint8_t const * const p_buf,
  198. uint32_t buf_len,
  199. uint32_t * const p_index,
  200. void * const p_void_struct)
  201. {
  202. SER_STRUCT_DEC_BEGIN(ble_gap_sec_keys_t);
  203. SER_PULL_COND(&(p_struct->p_enc_key), ble_gap_enc_key_t_dec);
  204. SER_PULL_COND(&(p_struct->p_id_key), ble_gap_id_key_t_dec);
  205. SER_PULL_COND(&(p_struct->p_sign_key), ble_gap_sign_info_t_dec);
  206. SER_PULL_COND(&(p_struct->p_pk), ble_gap_lesc_p256_pk_t_dec);
  207. SER_STRUCT_DEC_END;
  208. }
  209. uint32_t ble_gap_enc_info_t_enc(void const * const p_void_struct,
  210. uint8_t * const p_buf,
  211. uint32_t buf_len,
  212. uint32_t * const p_index)
  213. {
  214. SER_STRUCT_ENC_BEGIN(ble_gap_enc_info_t);
  215. SER_PUSH_uint8array(p_struct->ltk, BLE_GAP_SEC_KEY_LEN);
  216. uint8_t ser_data = (p_struct->lesc & 0x01)
  217. | ((p_struct->auth & 0x01) << 1)
  218. | ((p_struct->ltk_len & 0x3F) << 2);
  219. SER_PUSH_uint8(&ser_data);
  220. SER_STRUCT_ENC_END;
  221. }
  222. uint32_t ble_gap_enc_info_t_dec(uint8_t const * const p_buf,
  223. uint32_t buf_len,
  224. uint32_t * const p_index,
  225. void * const p_void_struct)
  226. {
  227. SER_STRUCT_DEC_BEGIN(ble_gap_enc_info_t);
  228. uint8_t ser_data;
  229. SER_PULL_uint8array(p_struct->ltk, BLE_GAP_SEC_KEY_LEN);
  230. SER_PULL_uint8(&ser_data);
  231. p_struct->lesc = ser_data & 0x01;
  232. p_struct->auth = (ser_data >> 1) & 0x01;
  233. p_struct->ltk_len = (ser_data >> 2) & 0x3F;
  234. SER_STRUCT_DEC_END;
  235. }
  236. uint32_t ble_gap_sign_info_t_enc(void const * const p_void_struct,
  237. uint8_t * const p_buf,
  238. uint32_t buf_len,
  239. uint32_t * const p_index)
  240. {
  241. SER_STRUCT_ENC_BEGIN(ble_gap_sign_info_t);
  242. SER_PUSH_uint8array(p_struct->csrk, BLE_GAP_SEC_KEY_LEN);
  243. SER_STRUCT_ENC_END;
  244. }
  245. uint32_t ble_gap_sign_info_t_dec(uint8_t const * const p_buf,
  246. uint32_t buf_len,
  247. uint32_t * const p_index,
  248. void * const p_void_struct)
  249. {
  250. SER_STRUCT_DEC_BEGIN(ble_gap_sign_info_t);
  251. SER_PULL_uint8array(p_struct->csrk, BLE_GAP_SEC_KEY_LEN);
  252. SER_STRUCT_ENC_END;
  253. }
  254. uint32_t ble_gap_evt_auth_status_t_enc(void const * const p_void_struct,
  255. uint8_t * const p_buf,
  256. uint32_t buf_len,
  257. uint32_t * const p_index)
  258. {
  259. SER_STRUCT_ENC_BEGIN(ble_gap_evt_auth_status_t);
  260. uint8_t ser_data = (p_struct->error_src) | ((p_struct->bonded) << 2);
  261. #if NRF_SD_BLE_API_VERSION >= 5
  262. ser_data |= ((p_struct->lesc) << 3);
  263. #endif
  264. SER_PUSH_uint8(&(p_struct->auth_status));
  265. SER_PUSH_uint8(&ser_data);
  266. SER_PUSH_FIELD(&(p_struct->sm1_levels), ble_gap_sec_levels_t_enc);
  267. SER_PUSH_FIELD(&(p_struct->sm2_levels), ble_gap_sec_levels_t_enc);
  268. SER_PUSH_FIELD(&(p_struct->kdist_own), ble_gap_sec_kdist_t_enc);
  269. SER_PUSH_FIELD(&(p_struct->kdist_peer), ble_gap_sec_kdist_t_enc);
  270. SER_STRUCT_ENC_END;
  271. }
  272. uint32_t ble_gap_evt_auth_status_t_dec(uint8_t const * const p_buf,
  273. uint32_t buf_len,
  274. uint32_t * const p_index,
  275. void * const p_void_struct)
  276. {
  277. SER_STRUCT_DEC_BEGIN(ble_gap_evt_auth_status_t);
  278. uint8_t ser_data;
  279. SER_PULL_uint8(&(p_struct->auth_status));
  280. SER_PULL_uint8(&ser_data);
  281. p_struct->error_src = ser_data & 0x03;
  282. p_struct->bonded = (ser_data >> 2) & 0x01;
  283. #if NRF_SD_BLE_API_VERSION >= 5
  284. p_struct->lesc = (ser_data >> 3) & 0x01;
  285. #endif
  286. SER_PULL_FIELD(&(p_struct->sm1_levels), ble_gap_sec_levels_t_dec);
  287. SER_PULL_FIELD(&(p_struct->sm2_levels), ble_gap_sec_levels_t_dec);
  288. SER_PULL_FIELD(&(p_struct->kdist_own), ble_gap_sec_kdist_t_dec);
  289. SER_PULL_FIELD(&(p_struct->kdist_peer), ble_gap_sec_kdist_t_dec);
  290. SER_STRUCT_DEC_END;
  291. }
  292. uint32_t ble_gap_conn_sec_mode_t_enc(void const * const p_void_struct,
  293. uint8_t * const p_buf,
  294. uint32_t buf_len,
  295. uint32_t * const p_index)
  296. {
  297. SER_STRUCT_ENC_BEGIN(ble_gap_conn_sec_mode_t);
  298. uint8_t ser_data = (p_struct->sm & 0x0F)
  299. | ((p_struct->lv & 0x0F) << 4);
  300. SER_PUSH_uint8(&ser_data);
  301. SER_STRUCT_ENC_END;
  302. }
  303. uint32_t ble_gap_conn_sec_mode_t_dec(uint8_t const * const p_buf,
  304. uint32_t buf_len,
  305. uint32_t * const p_index,
  306. void * const p_void_struct)
  307. {
  308. SER_STRUCT_DEC_BEGIN(ble_gap_conn_sec_mode_t);
  309. uint8_t ser_data;
  310. SER_PULL_uint8(&ser_data);
  311. p_struct->sm = ser_data & 0x0F;
  312. p_struct->lv = (ser_data >> 4) & 0x0F;
  313. SER_STRUCT_DEC_END;
  314. }
  315. uint32_t ble_gap_evt_conn_sec_update_t_enc(void const * const p_void_struct,
  316. uint8_t * const p_buf,
  317. uint32_t buf_len,
  318. uint32_t * const p_index)
  319. {
  320. SER_STRUCT_ENC_BEGIN(ble_gap_evt_conn_sec_update_t);
  321. SER_PUSH_FIELD(&(p_struct->conn_sec), ble_gap_conn_sec_t_enc);
  322. SER_STRUCT_ENC_END;
  323. }
  324. uint32_t ble_gap_evt_conn_sec_update_t_dec(uint8_t const * const p_buf,
  325. uint32_t buf_len,
  326. uint32_t * const p_index,
  327. void * const p_void_struct)
  328. {
  329. SER_STRUCT_DEC_BEGIN(ble_gap_evt_conn_sec_update_t);
  330. SER_PULL_FIELD(&(p_struct->conn_sec), ble_gap_conn_sec_t_dec);
  331. SER_STRUCT_DEC_END;
  332. }
  333. uint32_t ble_gap_conn_sec_t_enc(void const * const p_void_struct,
  334. uint8_t * const p_buf,
  335. uint32_t buf_len,
  336. uint32_t * const p_index)
  337. {
  338. SER_STRUCT_ENC_BEGIN(ble_gap_conn_sec_t);
  339. SER_PUSH_FIELD(&p_struct->sec_mode, ble_gap_conn_sec_mode_t_enc);
  340. SER_PUSH_uint8(&p_struct->encr_key_size);
  341. SER_STRUCT_ENC_END;
  342. }
  343. uint32_t ble_gap_conn_sec_t_dec(uint8_t const * const p_buf,
  344. uint32_t buf_len,
  345. uint32_t * const p_index,
  346. void * const p_void_struct)
  347. {
  348. SER_STRUCT_DEC_BEGIN(ble_gap_conn_sec_t);
  349. SER_PULL_FIELD(&p_struct->sec_mode, ble_gap_conn_sec_mode_t_dec);
  350. SER_PULL_uint8(&p_struct->encr_key_size);
  351. SER_STRUCT_DEC_END;
  352. }
  353. uint32_t ble_gap_evt_sec_info_request_t_enc(void const * const p_void_struct,
  354. uint8_t * const p_buf,
  355. uint32_t buf_len,
  356. uint32_t * const p_index)
  357. {
  358. SER_STRUCT_ENC_BEGIN(ble_gap_evt_sec_info_request_t);
  359. uint8_t ser_data = (p_struct->enc_info & 0x01)
  360. | ((p_struct->id_info & 0x01) << 1)
  361. | ((p_struct->sign_info& 0x01) << 2);
  362. SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc);
  363. SER_PUSH_FIELD(&p_struct->master_id, ble_gap_master_id_t_enc);
  364. SER_PUSH_uint8(&ser_data);
  365. SER_STRUCT_ENC_END;
  366. }
  367. uint32_t ble_gap_evt_sec_info_request_t_dec(uint8_t const * const p_buf,
  368. uint32_t buf_len,
  369. uint32_t * const p_index,
  370. void * const p_void_struct)
  371. {
  372. SER_STRUCT_DEC_BEGIN(ble_gap_evt_sec_info_request_t);
  373. uint8_t ser_data;
  374. SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec);
  375. SER_PULL_FIELD(&p_struct->master_id, ble_gap_master_id_t_dec);
  376. SER_PULL_uint8(&ser_data);
  377. p_struct->enc_info = ser_data & 0x01;
  378. p_struct->id_info = (ser_data >> 1) & 0x01;
  379. p_struct->sign_info = (ser_data >> 2) & 0x01;
  380. SER_STRUCT_DEC_END;
  381. }
  382. uint32_t ble_gap_evt_connected_t_enc(void const * const p_void_struct,
  383. uint8_t * const p_buf,
  384. uint32_t buf_len,
  385. uint32_t * const p_index)
  386. {
  387. SER_STRUCT_ENC_BEGIN(ble_gap_evt_connected_t);
  388. SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc);
  389. SER_PUSH_uint8(&p_struct->role);
  390. SER_PUSH_FIELD(&p_struct->conn_params, ble_gap_conn_params_t_enc);
  391. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  392. SER_PUSH_uint8(&p_struct->adv_handle);
  393. SER_PUSH_FIELD(&p_struct->adv_data, ble_gap_adv_data_t_enc);
  394. #endif
  395. SER_STRUCT_ENC_END;
  396. }
  397. uint32_t ble_gap_evt_connected_t_dec(uint8_t const * const p_buf,
  398. uint32_t buf_len,
  399. uint32_t * const p_index,
  400. void * const p_void_struct)
  401. {
  402. SER_STRUCT_DEC_BEGIN(ble_gap_evt_connected_t);
  403. SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec);
  404. SER_PULL_uint8(&p_struct->role);
  405. SER_PULL_FIELD(&p_struct->conn_params, ble_gap_conn_params_t_dec);
  406. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
  407. SER_PULL_uint8(&p_struct->adv_handle);
  408. SER_PULL_FIELD(&p_struct->adv_data, ble_gap_adv_data_t_dec);
  409. #endif
  410. SER_STRUCT_DEC_END;
  411. }
  412. uint32_t ble_gap_sec_params_t_enc(void const * const p_void_struct,
  413. uint8_t * const p_buf,
  414. uint32_t buf_len,
  415. uint32_t * const p_index)
  416. {
  417. SER_STRUCT_ENC_BEGIN(ble_gap_sec_params_t);
  418. uint8_t ser_data = (p_struct->bond & 0x01)
  419. | ((p_struct->mitm & 0x01) << 1)
  420. | ((p_struct->lesc & 0x01) << 2)
  421. | ((p_struct->keypress & 0x01) << 3)
  422. | ((p_struct->io_caps & 0x07) << 4)
  423. | ((p_struct->oob & 0x01) << 7);
  424. SER_PUSH_uint8(&ser_data);
  425. SER_PUSH_uint8(&p_struct->min_key_size);
  426. SER_PUSH_uint8(&p_struct->max_key_size);
  427. SER_PUSH_FIELD(&p_struct->kdist_own, ble_gap_sec_kdist_t_enc);
  428. SER_PUSH_FIELD(&p_struct->kdist_peer, ble_gap_sec_kdist_t_enc);
  429. SER_STRUCT_ENC_END;
  430. }
  431. uint32_t ble_gap_sec_params_t_dec(uint8_t const * const p_buf,
  432. uint32_t buf_len,
  433. uint32_t * const p_index,
  434. void * const p_void_struct)
  435. {
  436. SER_STRUCT_DEC_BEGIN(ble_gap_sec_params_t);
  437. uint8_t ser_data;
  438. SER_PULL_uint8(&ser_data);
  439. SER_PULL_uint8(&p_struct->min_key_size);
  440. SER_PULL_uint8(&p_struct->max_key_size);
  441. SER_PULL_FIELD(&p_struct->kdist_own, ble_gap_sec_kdist_t_dec);
  442. SER_PULL_FIELD(&p_struct->kdist_peer, ble_gap_sec_kdist_t_dec);
  443. p_struct->bond = ser_data & 0x01;
  444. p_struct->mitm = (ser_data >> 1) & 0x01;
  445. p_struct->lesc = (ser_data >> 2) & 0x01;
  446. p_struct->keypress = (ser_data >> 3) & 0x01;
  447. p_struct->io_caps = (ser_data >> 4) & 0x07;
  448. p_struct->oob = (ser_data >> 7) & 0x01;
  449. SER_STRUCT_DEC_END;
  450. }
  451. uint32_t ble_gap_evt_sec_params_request_t_enc(void const * const p_void_struct,
  452. uint8_t * const p_buf,
  453. uint32_t buf_len,
  454. uint32_t * const p_index)
  455. {
  456. SER_STRUCT_ENC_BEGIN(ble_gap_evt_sec_params_request_t);
  457. SER_PUSH_FIELD(&(p_struct->peer_params), ble_gap_sec_params_t_enc);
  458. SER_STRUCT_ENC_END;
  459. }
  460. uint32_t ble_gap_evt_sec_params_request_t_dec(uint8_t const * const p_buf,
  461. uint32_t buf_len,
  462. uint32_t * const p_index,
  463. void * const p_void_struct)
  464. {
  465. SER_STRUCT_DEC_BEGIN(ble_gap_evt_sec_params_request_t);
  466. SER_PULL_FIELD(&(p_struct->peer_params), ble_gap_sec_params_t_dec);
  467. SER_STRUCT_DEC_END;
  468. }
  469. uint32_t ble_gap_evt_conn_param_update_t_enc(void const * const p_void_struct,
  470. uint8_t * const p_buf,
  471. uint32_t buf_len,
  472. uint32_t * const p_index)
  473. {
  474. SER_STRUCT_ENC_BEGIN(ble_gap_evt_conn_param_update_t);
  475. SER_PUSH_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_enc);
  476. SER_STRUCT_ENC_END;
  477. }
  478. uint32_t ble_gap_evt_conn_param_update_t_dec(uint8_t const * const p_buf,
  479. uint32_t buf_len,
  480. uint32_t * const p_index,
  481. void * const p_void_struct)
  482. {
  483. SER_STRUCT_DEC_BEGIN(ble_gap_evt_conn_param_update_t);
  484. SER_PULL_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_dec);
  485. SER_STRUCT_DEC_END;
  486. }
  487. #ifndef S112
  488. uint32_t ble_gap_evt_conn_param_update_request_t_enc(void const * const p_void_struct,
  489. uint8_t * const p_buf,
  490. uint32_t buf_len,
  491. uint32_t * const p_index)
  492. {
  493. SER_STRUCT_ENC_BEGIN(ble_gap_evt_conn_param_update_request_t);
  494. SER_PUSH_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_enc);
  495. SER_STRUCT_ENC_END;
  496. }
  497. uint32_t ble_gap_evt_conn_param_update_request_t_dec(uint8_t const * const p_buf,
  498. uint32_t buf_len,
  499. uint32_t * const p_index,
  500. void * const p_void_struct)
  501. {
  502. SER_STRUCT_DEC_BEGIN(ble_gap_evt_conn_param_update_request_t);
  503. SER_PULL_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_dec);
  504. SER_STRUCT_DEC_END;
  505. }
  506. #endif //!S112
  507. uint32_t ble_gap_conn_params_t_enc(void const * const p_void_struct,
  508. uint8_t * const p_buf,
  509. uint32_t buf_len,
  510. uint32_t * const p_index)
  511. {
  512. SER_STRUCT_ENC_BEGIN(ble_gap_conn_params_t);
  513. SER_PUSH_uint16(&p_struct->min_conn_interval);
  514. SER_PUSH_uint16(&p_struct->max_conn_interval);
  515. SER_PUSH_uint16(&p_struct->slave_latency);
  516. SER_PUSH_uint16(&p_struct->conn_sup_timeout);
  517. SER_STRUCT_ENC_END;
  518. }
  519. uint32_t ble_gap_conn_params_t_dec(uint8_t const * const p_buf,
  520. uint32_t buf_len,
  521. uint32_t * const p_index,
  522. void * const p_void_struct)
  523. {
  524. SER_STRUCT_DEC_BEGIN(ble_gap_conn_params_t);
  525. SER_PULL_uint16(&p_struct->min_conn_interval);
  526. SER_PULL_uint16(&p_struct->max_conn_interval);
  527. SER_PULL_uint16(&p_struct->slave_latency);
  528. SER_PULL_uint16(&p_struct->conn_sup_timeout);
  529. SER_STRUCT_DEC_END;
  530. }
  531. uint32_t ble_gap_evt_disconnected_t_enc(void const * const p_void_struct,
  532. uint8_t * const p_buf,
  533. uint32_t buf_len,
  534. uint32_t * const p_index)
  535. {
  536. SER_STRUCT_ENC_BEGIN(ble_gap_evt_disconnected_t);
  537. SER_PUSH_uint8(&p_struct->reason);
  538. SER_STRUCT_ENC_END;
  539. }
  540. uint32_t ble_gap_evt_disconnected_t_dec(uint8_t const * const p_buf,
  541. uint32_t buf_len,
  542. uint32_t * const p_index,
  543. void * const p_void_struct)
  544. {
  545. SER_STRUCT_DEC_BEGIN(ble_gap_evt_disconnected_t);
  546. SER_PULL_uint8(&p_struct->reason);
  547. SER_STRUCT_DEC_END;
  548. }
  549. uint32_t ble_gap_master_id_t_enc(void const * const p_void_struct,
  550. uint8_t * const p_buf,
  551. uint32_t buf_len,
  552. uint32_t * const p_index)
  553. {
  554. SER_STRUCT_ENC_BEGIN(ble_gap_master_id_t);
  555. SER_PUSH_uint16(&p_struct->ediv);
  556. SER_PUSH_uint8array(p_struct->rand, BLE_GAP_SEC_RAND_LEN);
  557. SER_STRUCT_ENC_END;
  558. }
  559. uint32_t ble_gap_master_id_t_dec(uint8_t const * const p_buf,
  560. uint32_t buf_len,
  561. uint32_t * const p_index,
  562. void * const p_void_struct)
  563. {
  564. SER_STRUCT_DEC_BEGIN(ble_gap_master_id_t);
  565. SER_PULL_uint16(&p_struct->ediv);
  566. SER_PULL_uint8array(p_struct->rand, BLE_GAP_SEC_RAND_LEN);
  567. SER_STRUCT_DEC_END;
  568. }
  569. #ifndef S112
  570. uint32_t ble_gap_scan_params_t_enc(void const * const p_void_struct,
  571. uint8_t * const p_buf,
  572. uint32_t buf_len,
  573. uint32_t * const p_index)
  574. {
  575. SER_STRUCT_ENC_BEGIN(ble_gap_scan_params_t);
  576. uint8_t ser_data;
  577. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
  578. ser_data = (p_struct->active & 0x01)
  579. | ((p_struct->use_whitelist & 0x01) << 1)
  580. | ((p_struct->adv_dir_report & 0x01) << 2);
  581. SER_PUSH_uint8(&ser_data);
  582. #else
  583. ser_data =
  584. ((p_struct->extended & 0x01) << 0) |
  585. ((p_struct->report_incomplete_evts & 0x01) << 1) |
  586. ((p_struct->active & 0x01) << 2) |
  587. ((p_struct->filter_policy & 0x03) << 3);
  588. SER_PUSH_uint8(&ser_data);
  589. SER_PUSH_uint8(&p_struct->scan_phys);
  590. SER_PUSH_buf(p_struct->channel_mask, 5);
  591. #endif
  592. SER_PUSH_uint16(&p_struct->interval);
  593. SER_PUSH_uint16(&p_struct->window);
  594. SER_PUSH_uint16(&p_struct->timeout);
  595. SER_STRUCT_ENC_END;
  596. }
  597. uint32_t ble_gap_scan_params_t_dec(uint8_t const * const p_buf,
  598. uint32_t buf_len,
  599. uint32_t * const p_index,
  600. void * const p_void_struct)
  601. {
  602. SER_STRUCT_DEC_BEGIN(ble_gap_scan_params_t);
  603. uint8_t ser_data;
  604. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
  605. SER_PULL_uint8(&ser_data);
  606. p_struct->active = ser_data & 0x01;
  607. p_struct->use_whitelist = (ser_data >> 1) & 0x01;
  608. p_struct->adv_dir_report = (ser_data >> 2) & 0x01;
  609. #else
  610. SER_PULL_uint8(&ser_data);
  611. p_struct->extended = ser_data & 0x01;
  612. p_struct->report_incomplete_evts = (ser_data >> 1) & 0x01;
  613. p_struct->active = (ser_data >> 2) & 0x01;
  614. p_struct->filter_policy = (ser_data >> 3) & 0x03;
  615. SER_PULL_uint8(&p_struct->scan_phys);
  616. uint8_t * p_channel_mask = (uint8_t *)p_struct->channel_mask;
  617. SER_PULL_buf(&p_channel_mask, 5, 5);
  618. #endif
  619. SER_PULL_uint16(&p_struct->interval);
  620. SER_PULL_uint16(&p_struct->window);
  621. SER_PULL_uint16(&p_struct->timeout);
  622. SER_STRUCT_DEC_END;
  623. }
  624. #endif //!S112
  625. uint32_t ble_gap_enc_key_t_enc(void const * const p_void_struct,
  626. uint8_t * const p_buf,
  627. uint32_t buf_len,
  628. uint32_t * const p_index)
  629. {
  630. SER_STRUCT_ENC_BEGIN(ble_gap_enc_key_t);
  631. SER_PUSH_FIELD(&p_struct->enc_info, ble_gap_enc_info_t_enc);
  632. SER_PUSH_FIELD(&p_struct->master_id, ble_gap_master_id_t_enc);
  633. SER_STRUCT_ENC_END;
  634. }
  635. uint32_t ble_gap_enc_key_t_dec(uint8_t const * const p_buf,
  636. uint32_t buf_len,
  637. uint32_t * const p_index,
  638. void * const p_void_struct)
  639. {
  640. SER_STRUCT_DEC_BEGIN(ble_gap_enc_key_t);
  641. SER_PULL_FIELD(&p_struct->enc_info, ble_gap_enc_info_t_dec);
  642. SER_PULL_FIELD(&p_struct->master_id, ble_gap_master_id_t_dec);
  643. SER_STRUCT_DEC_END;
  644. }
  645. uint32_t ble_gap_id_key_t_enc(void const * const p_void_struct,
  646. uint8_t * const p_buf,
  647. uint32_t buf_len,
  648. uint32_t * const p_index)
  649. {
  650. SER_STRUCT_ENC_BEGIN(ble_gap_id_key_t);
  651. SER_PUSH_FIELD(&p_struct->id_info, ble_gap_irk_t_enc);
  652. SER_PUSH_FIELD(&p_struct->id_addr_info, ble_gap_addr_t_enc);
  653. SER_STRUCT_ENC_END;
  654. }
  655. uint32_t ble_gap_id_key_t_dec(uint8_t const * const p_buf,
  656. uint32_t buf_len,
  657. uint32_t * const p_index,
  658. void * const p_void_struct)
  659. {
  660. SER_STRUCT_DEC_BEGIN(ble_gap_id_key_t);
  661. SER_PULL_FIELD(&p_struct->id_info, ble_gap_irk_t_dec);
  662. SER_PULL_FIELD(&p_struct->id_addr_info, ble_gap_addr_t_dec);
  663. SER_STRUCT_DEC_END;
  664. }
  665. uint32_t ble_gap_sec_keyset_t_enc(void const * const p_void_struct,
  666. uint8_t * const p_buf,
  667. uint32_t buf_len,
  668. uint32_t * const p_index)
  669. {
  670. SER_STRUCT_ENC_BEGIN(ble_gap_sec_keyset_t);
  671. SER_PUSH_FIELD(&p_struct->keys_own, ble_gap_sec_keys_t_enc);
  672. SER_PUSH_FIELD(&p_struct->keys_peer, ble_gap_sec_keys_t_enc);
  673. SER_STRUCT_ENC_END;
  674. }
  675. uint32_t ble_gap_sec_keyset_t_dec(uint8_t const * const p_buf,
  676. uint32_t buf_len,
  677. uint32_t * const p_index,
  678. void * const p_void_struct)
  679. {
  680. SER_STRUCT_DEC_BEGIN(ble_gap_sec_keyset_t);
  681. SER_PULL_FIELD(&p_struct->keys_own, ble_gap_sec_keys_t_dec);
  682. SER_PULL_FIELD(&p_struct->keys_peer, ble_gap_sec_keys_t_dec);
  683. SER_STRUCT_DEC_END;
  684. }
  685. uint32_t ble_gap_evt_sec_request_t_enc(void const * const p_void_struct,
  686. uint8_t * const p_buf,
  687. uint32_t buf_len,
  688. uint32_t * const p_index)
  689. {
  690. SER_STRUCT_ENC_BEGIN(ble_gap_evt_sec_request_t);
  691. uint8_t ser_data = (p_struct->bond & 0x01)
  692. | ((p_struct->mitm & 0x01) << 1)
  693. | ((p_struct->lesc & 0x01) << 2)
  694. | ((p_struct->keypress & 0x01) << 3);
  695. SER_PUSH_uint8(&ser_data);
  696. SER_STRUCT_ENC_END;
  697. }
  698. uint32_t ble_gap_evt_sec_request_t_dec(uint8_t const * const p_buf,
  699. uint32_t buf_len,
  700. uint32_t * const p_index,
  701. void * const p_void_struct)
  702. {
  703. SER_STRUCT_DEC_BEGIN(ble_gap_evt_sec_request_t);
  704. uint8_t ser_data;
  705. SER_PULL_uint8(&ser_data);
  706. p_struct->bond = ser_data & 0x01;
  707. p_struct->mitm = (ser_data >> 1) & 0x01;
  708. p_struct->lesc = (ser_data >> 2) & 0x01;
  709. p_struct->keypress = (ser_data >> 3) & 0x01;
  710. SER_STRUCT_DEC_END;
  711. }
  712. uint32_t ble_gap_sec_kdist_t_enc(void const * const p_void_struct,
  713. uint8_t * const p_buf,
  714. uint32_t buf_len,
  715. uint32_t * const p_index)
  716. {
  717. SER_STRUCT_ENC_BEGIN(ble_gap_sec_kdist_t);
  718. uint8_t ser_data = (p_struct->enc & 0x01)
  719. | (p_struct->id & 0x01) << 1
  720. | (p_struct->sign & 0x01) << 2
  721. | (p_struct->link & 0x01) << 3;
  722. SER_PUSH_uint8(&ser_data);
  723. SER_STRUCT_ENC_END;
  724. }
  725. uint32_t ble_gap_sec_kdist_t_dec(uint8_t const * const p_buf,
  726. uint32_t buf_len,
  727. uint32_t * const p_index,
  728. void * const p_void_struct)
  729. {
  730. SER_STRUCT_DEC_BEGIN(ble_gap_sec_kdist_t);
  731. uint8_t ser_data;
  732. SER_PULL_uint8(&ser_data);
  733. p_struct->enc = ser_data & 0x01;
  734. p_struct->id = (ser_data >> 1) & 0x01;
  735. p_struct->sign = (ser_data >> 2) & 0x01;
  736. p_struct->link = (ser_data >> 3) & 0x01;
  737. SER_STRUCT_DEC_END;
  738. }
  739. uint32_t ble_gap_opt_ch_map_t_enc(void const * const p_void_struct,
  740. uint8_t * const p_buf,
  741. uint32_t buf_len,
  742. uint32_t * const p_index)
  743. {
  744. SER_STRUCT_ENC_BEGIN(ble_gap_opt_ch_map_t);
  745. SER_PUSH_uint16(&p_struct->conn_handle);
  746. SER_PUSH_uint8array(p_struct->ch_map, 5);
  747. SER_STRUCT_ENC_END;
  748. }
  749. uint32_t ble_gap_opt_ch_map_t_dec(uint8_t const * const p_buf,
  750. uint32_t buf_len,
  751. uint32_t * const p_index,
  752. void * const p_void_struct)
  753. {
  754. SER_STRUCT_DEC_BEGIN(ble_gap_opt_ch_map_t);
  755. SER_PULL_uint16(&p_struct->conn_handle);
  756. SER_PULL_uint8array(p_struct->ch_map, 5);
  757. SER_STRUCT_DEC_END;
  758. }
  759. uint32_t ble_gap_opt_local_conn_latency_t_enc(void const * const p_void_struct,
  760. uint8_t * const p_buf,
  761. uint32_t buf_len,
  762. uint32_t * const p_index)
  763. {
  764. SER_STRUCT_ENC_BEGIN(ble_gap_opt_local_conn_latency_t);
  765. SER_PUSH_uint16(&p_struct->conn_handle);
  766. SER_PUSH_uint16(&p_struct->requested_latency);
  767. SER_PUSH_COND(p_struct->p_actual_latency, uint16_t_enc);
  768. SER_STRUCT_ENC_END;
  769. }
  770. uint32_t ble_gap_opt_local_conn_latency_t_dec(uint8_t const * const p_buf,
  771. uint32_t buf_len,
  772. uint32_t * const p_index,
  773. void * const p_void_struct)
  774. {
  775. SER_STRUCT_DEC_BEGIN(ble_gap_opt_local_conn_latency_t);
  776. SER_PULL_uint16(&p_struct->conn_handle);
  777. SER_PULL_uint16(&p_struct->requested_latency);
  778. SER_PULL_COND(&p_struct->p_actual_latency, uint16_t_dec);
  779. SER_STRUCT_DEC_END;
  780. }
  781. uint32_t ble_gap_opt_passkey_t_enc(void const * const p_void_struct,
  782. uint8_t * const p_buf,
  783. uint32_t buf_len,
  784. uint32_t * const p_index)
  785. {
  786. SER_STRUCT_ENC_BEGIN(ble_gap_opt_passkey_t);
  787. SER_PUSH_buf(p_struct->p_passkey, BLE_GAP_PASSKEY_LEN);
  788. SER_STRUCT_ENC_END;
  789. }
  790. uint32_t ble_gap_opt_passkey_t_dec(uint8_t const * const p_buf,
  791. uint32_t buf_len,
  792. uint32_t * const p_index,
  793. void * const p_void_struct)
  794. {
  795. SER_STRUCT_DEC_BEGIN(ble_gap_opt_passkey_t);
  796. SER_PULL_buf((uint8_t**)&p_struct->p_passkey, BLE_GAP_PASSKEY_LEN, BLE_GAP_PASSKEY_LEN);
  797. SER_STRUCT_DEC_END;
  798. }
  799. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
  800. uint32_t ble_gap_opt_scan_req_report_t_enc(void const * const p_void_struct,
  801. uint8_t * const p_buf,
  802. uint32_t buf_len,
  803. uint32_t * const p_index)
  804. {
  805. SER_STRUCT_ENC_BEGIN(ble_gap_opt_scan_req_report_t);
  806. uint8_t ser_data = p_struct->enable & 0x01;
  807. SER_PUSH_uint8(&ser_data);
  808. SER_STRUCT_ENC_END;
  809. }
  810. uint32_t ble_gap_opt_scan_req_report_t_dec(uint8_t const * const p_buf,
  811. uint32_t buf_len,
  812. uint32_t * const p_index,
  813. void * const p_void_struct)
  814. {
  815. SER_STRUCT_DEC_BEGIN(ble_gap_opt_scan_req_report_t);
  816. uint8_t ser_data;
  817. SER_PULL_uint8(&ser_data);
  818. p_struct->enable = ser_data & 0x01;
  819. SER_STRUCT_DEC_END;
  820. }
  821. #endif
  822. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  823. uint32_t ble_gap_opt_compat_mode_t_enc(void const * const p_void_struct,
  824. uint8_t * const p_buf,
  825. uint32_t buf_len,
  826. uint32_t * const p_index)
  827. {
  828. SER_STRUCT_ENC_BEGIN(ble_gap_opt_compat_mode_t);
  829. uint8_t ser_data = p_struct->mode_1_enable & 0x01;
  830. SER_PUSH_uint8(&ser_data);
  831. SER_STRUCT_ENC_END;
  832. }
  833. uint32_t ble_gap_opt_compat_mode_t_dec(uint8_t const * const p_buf,
  834. uint32_t buf_len,
  835. uint32_t * const p_index,
  836. void * const p_void_struct)
  837. {
  838. SER_STRUCT_DEC_BEGIN(ble_gap_opt_compat_mode_t);
  839. uint8_t ser_data;
  840. SER_PULL_uint8(&ser_data);
  841. p_struct->mode_1_enable = ser_data & 0x01;
  842. SER_STRUCT_DEC_END;
  843. }
  844. #endif
  845. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
  846. uint32_t ble_gap_adv_ch_mask_t_enc(void const * const p_void_struct,
  847. uint8_t * const p_buf,
  848. uint32_t buf_len,
  849. uint32_t * const p_index)
  850. {
  851. SER_STRUCT_ENC_BEGIN(ble_gap_adv_ch_mask_t);
  852. uint8_t ser_data = (p_struct->ch_37_off & 0x01)
  853. | ((p_struct->ch_38_off & 0x01) << 1)
  854. | ((p_struct->ch_39_off & 0x01) << 2);
  855. SER_PUSH_uint8(&ser_data);
  856. SER_STRUCT_ENC_END;
  857. }
  858. uint32_t ble_gap_adv_ch_mask_t_dec(uint8_t const * const p_buf,
  859. uint32_t buf_len,
  860. uint32_t * const p_index,
  861. void * const p_void_struct)
  862. {
  863. SER_STRUCT_DEC_BEGIN(ble_gap_adv_ch_mask_t);
  864. uint8_t ser_data;
  865. SER_PULL_uint8(&ser_data);
  866. p_struct->ch_37_off = ser_data & 0x01;
  867. p_struct->ch_38_off = (ser_data >> 1) & 0x01;
  868. p_struct->ch_39_off = (ser_data >> 2) & 0x01;
  869. SER_STRUCT_DEC_END;
  870. }
  871. #endif
  872. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  873. uint32_t ble_gap_enable_params_t_enc(void const * const p_void_struct,
  874. uint8_t * const p_buf,
  875. uint32_t buf_len,
  876. uint32_t * const p_index)
  877. {
  878. SER_STRUCT_ENC_BEGIN(ble_gap_enable_params_t);
  879. SER_PUSH_uint8(&p_struct->periph_conn_count);
  880. SER_PUSH_uint8(&p_struct->central_conn_count);
  881. SER_PUSH_uint8(&p_struct->central_sec_count);
  882. SER_PUSH_COND(p_struct->p_device_name, ble_gap_device_name_t_enc);
  883. SER_STRUCT_ENC_END;
  884. }
  885. uint32_t ble_gap_enable_params_t_dec(uint8_t const * const p_buf,
  886. uint32_t buf_len,
  887. uint32_t * const p_index,
  888. void * const p_void_struct)
  889. {
  890. SER_STRUCT_DEC_BEGIN(ble_gap_enable_params_t);
  891. SER_PULL_uint8(&p_struct->periph_conn_count);
  892. SER_PULL_uint8(&p_struct->central_conn_count);
  893. SER_PULL_uint8(&p_struct->central_sec_count);
  894. SER_PULL_COND(&p_struct->p_device_name, ble_gap_device_name_t_dec);
  895. SER_STRUCT_DEC_END;
  896. }
  897. #endif
  898. uint32_t ble_gap_lesc_p256_pk_t_enc(void const * const p_void_struct,
  899. uint8_t * const p_buf,
  900. uint32_t buf_len,
  901. uint32_t * const p_index)
  902. {
  903. SER_STRUCT_ENC_BEGIN(ble_gap_lesc_p256_pk_t);
  904. SER_PUSH_uint8array(p_struct->pk, BLE_GAP_LESC_P256_PK_LEN);
  905. SER_STRUCT_ENC_END;
  906. }
  907. uint32_t ble_gap_lesc_p256_pk_t_dec(uint8_t const * const p_buf,
  908. uint32_t buf_len,
  909. uint32_t * const p_index,
  910. void * const p_void_struct)
  911. {
  912. SER_STRUCT_DEC_BEGIN(ble_gap_lesc_p256_pk_t);
  913. SER_PULL_uint8array(p_struct->pk, BLE_GAP_LESC_P256_PK_LEN);
  914. SER_STRUCT_DEC_END;
  915. }
  916. uint32_t ble_gap_lesc_dhkey_t_enc(void const * const p_void_struct,
  917. uint8_t * const p_buf,
  918. uint32_t buf_len,
  919. uint32_t * const p_index)
  920. {
  921. SER_STRUCT_ENC_BEGIN(ble_gap_lesc_dhkey_t);
  922. SER_PUSH_uint8array(p_struct->key, BLE_GAP_LESC_DHKEY_LEN);
  923. SER_STRUCT_ENC_END;
  924. }
  925. uint32_t ble_gap_lesc_dhkey_t_dec(uint8_t const * const p_buf,
  926. uint32_t buf_len,
  927. uint32_t * const p_index,
  928. void * const p_void_struct)
  929. {
  930. SER_STRUCT_DEC_BEGIN(ble_gap_lesc_dhkey_t);
  931. SER_PULL_uint8array(p_struct->key, BLE_GAP_LESC_DHKEY_LEN);
  932. SER_STRUCT_DEC_END;
  933. }
  934. uint32_t ble_gap_lesc_oob_data_t_enc(void const * const p_void_struct,
  935. uint8_t * const p_buf,
  936. uint32_t buf_len,
  937. uint32_t * const p_index)
  938. {
  939. SER_STRUCT_ENC_BEGIN(ble_gap_lesc_oob_data_t);
  940. SER_PUSH_FIELD(&p_struct->addr, ble_gap_addr_t_enc);
  941. SER_PUSH_uint8array(p_struct->r, BLE_GAP_SEC_KEY_LEN);
  942. SER_PUSH_uint8array(p_struct->c, BLE_GAP_SEC_KEY_LEN);
  943. SER_STRUCT_ENC_END;
  944. }
  945. uint32_t ble_gap_lesc_oob_data_t_dec(uint8_t const * const p_buf,
  946. uint32_t buf_len,
  947. uint32_t * const p_index,
  948. void * const p_void_struct)
  949. {
  950. SER_STRUCT_DEC_BEGIN(ble_gap_lesc_oob_data_t);
  951. SER_PULL_FIELD(&p_struct->addr, ble_gap_addr_t_dec);
  952. SER_PULL_uint8array(p_struct->r, BLE_GAP_SEC_KEY_LEN);
  953. SER_PULL_uint8array(p_struct->c, BLE_GAP_SEC_KEY_LEN);
  954. SER_STRUCT_DEC_END;
  955. }
  956. uint32_t ble_gap_adv_params_t_enc(void const * const p_void_struct,
  957. uint8_t * const p_buf,
  958. uint32_t buf_len,
  959. uint32_t * const p_index)
  960. {
  961. SER_STRUCT_ENC_BEGIN(ble_gap_adv_params_t);
  962. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
  963. SER_PUSH_uint8(&p_struct->type);
  964. SER_PUSH_COND(p_struct->p_peer_addr, ble_gap_addr_t_enc);
  965. SER_PUSH_uint8(&p_struct->fp);
  966. SER_PUSH_uint16(&p_struct->interval);
  967. SER_PUSH_uint16(&p_struct->timeout);
  968. SER_PUSH_FIELD(&p_struct->channel_mask, ble_gap_adv_ch_mask_t_enc);
  969. #else
  970. SER_PUSH_FIELD(&p_struct->properties, ble_gap_adv_properties_t_enc);
  971. SER_PUSH_COND(p_struct->p_peer_addr, ble_gap_addr_t_enc);
  972. SER_PUSH_uint32(&p_struct->interval);
  973. SER_PUSH_uint16(&p_struct->duration);
  974. SER_PUSH_uint8(&p_struct->max_adv_evts);
  975. SER_PUSH_buf(p_struct->channel_mask, 5);
  976. SER_PUSH_uint8(&p_struct->filter_policy);
  977. SER_PUSH_uint8(&p_struct->primary_phy);
  978. SER_PUSH_uint8(&p_struct->secondary_phy);
  979. uint8_t temp = p_struct->set_id | (p_struct->scan_req_notification << 4);
  980. SER_PUSH_uint8(&temp);
  981. #endif
  982. SER_STRUCT_ENC_END;
  983. }
  984. uint32_t ble_gap_adv_params_t_dec(uint8_t const * const p_buf,
  985. uint32_t buf_len,
  986. uint32_t * const p_index,
  987. void * const p_void_struct)
  988. {
  989. SER_STRUCT_DEC_BEGIN(ble_gap_adv_params_t);
  990. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
  991. SER_PULL_uint8(&p_struct->type);
  992. SER_PULL_COND(&p_struct->p_peer_addr, ble_gap_addr_t_dec);
  993. SER_PULL_uint8(&p_struct->fp);
  994. SER_PULL_uint16(&p_struct->interval);
  995. SER_PULL_uint16(&p_struct->timeout);
  996. SER_PULL_FIELD(&p_struct->channel_mask, ble_gap_adv_ch_mask_t_dec);
  997. #else
  998. SER_PULL_FIELD(&p_struct->properties, ble_gap_adv_properties_t_dec);
  999. SER_PULL_COND(&p_struct->p_peer_addr, ble_gap_addr_t_dec);
  1000. SER_PULL_uint32(&p_struct->interval);
  1001. SER_PULL_uint16(&p_struct->duration);
  1002. SER_PULL_uint8(&p_struct->max_adv_evts);
  1003. uint8_t * p_channel_mask = p_struct->channel_mask;
  1004. SER_PULL_buf((uint8_t **)&p_channel_mask, 5, 5);
  1005. SER_PULL_uint8(&p_struct->filter_policy);
  1006. SER_PULL_uint8(&p_struct->primary_phy);
  1007. SER_PULL_uint8(&p_struct->secondary_phy);
  1008. uint8_t temp;
  1009. SER_PULL_uint8(&temp);
  1010. p_struct->set_id = temp & 0x0F;
  1011. p_struct->scan_req_notification = (temp & 0x10) ? 1 : 0;
  1012. #endif
  1013. SER_STRUCT_DEC_END;
  1014. }
  1015. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  1016. uint32_t ble_gap_opt_ext_len_t_enc(void const * const p_void_struct,
  1017. uint8_t * const p_buf,
  1018. uint32_t buf_len,
  1019. uint32_t * const p_index)
  1020. {
  1021. SER_STRUCT_ENC_BEGIN(ble_gap_opt_ext_len_t);
  1022. SER_PUSH_uint8(&p_struct->rxtx_max_pdu_payload_size);
  1023. SER_STRUCT_ENC_END;
  1024. }
  1025. uint32_t ble_gap_opt_ext_len_t_dec(uint8_t const * const p_buf,
  1026. uint32_t buf_len,
  1027. uint32_t * const p_index,
  1028. void * const p_void_struct)
  1029. {
  1030. SER_STRUCT_DEC_BEGIN(ble_gap_opt_ext_len_t);
  1031. SER_PULL_uint8(&p_struct->rxtx_max_pdu_payload_size);
  1032. SER_STRUCT_DEC_END;
  1033. }
  1034. #endif
  1035. uint32_t ble_gap_opt_auth_payload_timeout_t_enc(void const * const p_void_struct,
  1036. uint8_t * const p_buf,
  1037. uint32_t buf_len,
  1038. uint32_t * const p_index)
  1039. {
  1040. SER_STRUCT_ENC_BEGIN(ble_gap_opt_auth_payload_timeout_t);
  1041. SER_PUSH_uint16(&p_struct->conn_handle);
  1042. SER_PUSH_uint16(&p_struct->auth_payload_timeout);
  1043. SER_STRUCT_ENC_END;
  1044. }
  1045. uint32_t ble_gap_opt_auth_payload_timeout_t_dec(uint8_t const * const p_buf,
  1046. uint32_t buf_len,
  1047. uint32_t * const p_index,
  1048. void * const p_void_struct)
  1049. {
  1050. SER_STRUCT_DEC_BEGIN(ble_gap_opt_auth_payload_timeout_t);
  1051. SER_PULL_uint16(&p_struct->conn_handle);
  1052. SER_PULL_uint16(&p_struct->auth_payload_timeout);
  1053. SER_STRUCT_DEC_END;
  1054. }
  1055. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  1056. uint32_t ble_gap_device_name_t_enc
  1057. #else
  1058. uint32_t ble_gap_cfg_device_name_t_enc
  1059. #endif
  1060. (void const * const p_void_struct,
  1061. uint8_t * const p_buf,
  1062. uint32_t buf_len,
  1063. uint32_t * const p_index)
  1064. {
  1065. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  1066. SER_STRUCT_ENC_BEGIN(ble_gap_device_name_t);
  1067. #else
  1068. SER_STRUCT_ENC_BEGIN(ble_gap_cfg_device_name_t);
  1069. #endif
  1070. /* serializer does not support attributes on stack */
  1071. if (p_struct->vloc != BLE_GATTS_VLOC_STACK)
  1072. {
  1073. err_code = NRF_ERROR_INVALID_PARAM;
  1074. }
  1075. SER_PUSH_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_enc);
  1076. uint8_t ser_data = p_struct->vloc & 0x03;
  1077. SER_PUSH_uint8(&ser_data);
  1078. SER_PUSH_uint16(&p_struct->current_len);
  1079. SER_PUSH_uint16(&p_struct->max_len);
  1080. SER_PUSH_buf(p_struct->p_value, p_struct->current_len);
  1081. SER_STRUCT_ENC_END;
  1082. }
  1083. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  1084. uint32_t ble_gap_device_name_t_dec
  1085. #else
  1086. uint32_t ble_gap_cfg_device_name_t_dec
  1087. #endif
  1088. (uint8_t const * const p_buf,
  1089. uint32_t buf_len,
  1090. uint32_t * const p_index,
  1091. void * const p_void_struct)
  1092. {
  1093. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  1094. SER_STRUCT_DEC_BEGIN(ble_gap_device_name_t);
  1095. #else
  1096. SER_STRUCT_DEC_BEGIN(ble_gap_cfg_device_name_t);
  1097. #endif
  1098. uint16_t value_max_len = p_struct->max_len;
  1099. uint8_t ser_data;
  1100. SER_PULL_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_dec);
  1101. SER_PULL_uint8(&ser_data);
  1102. p_struct->vloc = ser_data & 0x03;
  1103. SER_PULL_uint16(&p_struct->current_len);
  1104. SER_PULL_uint16(&p_struct->max_len);
  1105. SER_PULL_buf(&p_struct->p_value,value_max_len, p_struct->current_len);
  1106. SER_STRUCT_DEC_END;
  1107. }
  1108. uint32_t ble_gap_privacy_params_t_enc(void const * const p_void_struct,
  1109. uint8_t * const p_buf,
  1110. uint32_t buf_len,
  1111. uint32_t * const p_index)
  1112. {
  1113. SER_STRUCT_ENC_BEGIN(ble_gap_privacy_params_t);
  1114. SER_PUSH_uint8(&p_struct->privacy_mode);
  1115. SER_PUSH_uint8(&p_struct->private_addr_type);
  1116. SER_PUSH_uint16(&p_struct->private_addr_cycle_s);
  1117. SER_PUSH_COND(p_struct->p_device_irk, ble_gap_irk_t_enc);
  1118. SER_STRUCT_ENC_END;
  1119. }
  1120. uint32_t ble_gap_privacy_params_t_dec(uint8_t const * const p_buf,
  1121. uint32_t buf_len,
  1122. uint32_t * const p_index,
  1123. void * const p_void_struct)
  1124. {
  1125. SER_STRUCT_DEC_BEGIN(ble_gap_privacy_params_t);
  1126. SER_PULL_uint8(&p_struct->privacy_mode);
  1127. SER_PULL_uint8(&p_struct->private_addr_type);
  1128. SER_PULL_uint16(&p_struct->private_addr_cycle_s);
  1129. SER_PULL_COND(&p_struct->p_device_irk, ble_gap_irk_t_dec);
  1130. SER_STRUCT_DEC_END;
  1131. }
  1132. #if NRF_SD_BLE_API_VERSION >= 4
  1133. #ifndef S112
  1134. uint32_t ble_gap_opt_compat_mode_1_t_enc(void const * const p_void_struct,
  1135. uint8_t * const p_buf,
  1136. uint32_t buf_len,
  1137. uint32_t * const p_index)
  1138. {
  1139. SER_STRUCT_ENC_BEGIN(ble_gap_opt_compat_mode_1_t);
  1140. uint8_t enable = p_struct->enable;
  1141. SER_PUSH_uint8(&enable);
  1142. SER_STRUCT_ENC_END;
  1143. }
  1144. uint32_t ble_gap_opt_compat_mode_1_t_dec(uint8_t const * const p_buf,
  1145. uint32_t buf_len,
  1146. uint32_t * const p_index,
  1147. void * const p_void_struct)
  1148. {
  1149. SER_STRUCT_DEC_BEGIN(ble_gap_opt_compat_mode_1_t);
  1150. uint8_t enable;
  1151. SER_PULL_uint8(&enable);
  1152. p_struct->enable = enable;
  1153. SER_STRUCT_DEC_END;
  1154. }
  1155. #endif //!S112
  1156. uint32_t ble_gap_opt_slave_latency_disable_t_enc(void const * const p_void_struct,
  1157. uint8_t * const p_buf,
  1158. uint32_t buf_len,
  1159. uint32_t * const p_index)
  1160. {
  1161. SER_STRUCT_ENC_BEGIN(ble_gap_opt_slave_latency_disable_t);
  1162. SER_PUSH_uint16(&p_struct->conn_handle);
  1163. uint8_t disable = p_struct->disable;
  1164. SER_PUSH_uint8(&disable);
  1165. SER_STRUCT_ENC_END;
  1166. }
  1167. uint32_t ble_gap_opt_slave_latency_disable_t_dec(uint8_t const * const p_buf,
  1168. uint32_t buf_len,
  1169. uint32_t * const p_index,
  1170. void * const p_void_struct)
  1171. {
  1172. SER_STRUCT_DEC_BEGIN(ble_gap_opt_slave_latency_disable_t);
  1173. SER_PULL_uint16(&p_struct->conn_handle);
  1174. uint8_t disable;
  1175. SER_PULL_uint8(&disable);
  1176. p_struct->disable = disable;
  1177. SER_STRUCT_DEC_END;
  1178. }
  1179. uint32_t ble_gap_conn_cfg_t_enc(void const * const p_void_struct,
  1180. uint8_t * const p_buf,
  1181. uint32_t buf_len,
  1182. uint32_t * const p_index)
  1183. {
  1184. SER_STRUCT_ENC_BEGIN(ble_gap_conn_cfg_t);
  1185. SER_PUSH_uint8(&p_struct->conn_count);
  1186. SER_PUSH_uint16(&p_struct->event_length);
  1187. SER_STRUCT_ENC_END;
  1188. }
  1189. uint32_t ble_gap_conn_cfg_t_dec(uint8_t const * const p_buf,
  1190. uint32_t buf_len,
  1191. uint32_t * const p_index,
  1192. void * const p_void_struct)
  1193. {
  1194. SER_STRUCT_DEC_BEGIN(ble_gap_conn_cfg_t);
  1195. SER_PULL_uint8(&p_struct->conn_count);
  1196. SER_PULL_uint16(&p_struct->event_length);
  1197. SER_STRUCT_DEC_END;
  1198. }
  1199. uint32_t ble_gap_cfg_role_count_t_enc(void const * const p_void_struct,
  1200. uint8_t * const p_buf,
  1201. uint32_t buf_len,
  1202. uint32_t * const p_index)
  1203. {
  1204. SER_STRUCT_ENC_BEGIN(ble_gap_cfg_role_count_t);
  1205. SER_PUSH_uint8(&p_struct->periph_role_count);
  1206. #ifndef S112
  1207. SER_PUSH_uint8(&p_struct->central_role_count);
  1208. SER_PUSH_uint8(&p_struct->central_sec_count);
  1209. #endif //!S112
  1210. #if NRF_SD_BLE_API_VERSION > 5
  1211. SER_PUSH_uint8(&p_struct->adv_set_count);
  1212. #ifndef S112
  1213. uint32_t temp = p_struct->qos_channel_survey_role_available;
  1214. SER_PUSH_uint8(&temp);
  1215. #endif //!S112
  1216. #endif
  1217. SER_STRUCT_ENC_END;
  1218. }
  1219. uint32_t ble_gap_cfg_role_count_t_dec(uint8_t const * const p_buf,
  1220. uint32_t buf_len,
  1221. uint32_t * const p_index,
  1222. void * const p_void_struct)
  1223. {
  1224. SER_STRUCT_DEC_BEGIN(ble_gap_cfg_role_count_t);
  1225. SER_PULL_uint8(&p_struct->periph_role_count);
  1226. #ifndef S112
  1227. SER_PULL_uint8(&p_struct->central_role_count);
  1228. SER_PULL_uint8(&p_struct->central_sec_count);
  1229. #endif //!S112
  1230. #if NRF_SD_BLE_API_VERSION > 5
  1231. SER_PULL_uint8(&p_struct->adv_set_count);
  1232. #ifndef S112
  1233. uint8_t temp;
  1234. SER_PULL_uint8(&temp);
  1235. p_struct->qos_channel_survey_role_available = temp;
  1236. #endif //!S112
  1237. #endif
  1238. SER_STRUCT_DEC_END;
  1239. }
  1240. #ifndef S112
  1241. uint32_t ble_gap_data_length_params_t_enc(void const * const p_void_struct,
  1242. uint8_t * const p_buf,
  1243. uint32_t buf_len,
  1244. uint32_t * const p_index)
  1245. {
  1246. SER_STRUCT_ENC_BEGIN(ble_gap_data_length_params_t);
  1247. SER_PUSH_uint16(&p_struct->max_tx_octets);
  1248. SER_PUSH_uint16(&p_struct->max_rx_octets);
  1249. SER_PUSH_uint16(&p_struct->max_tx_time_us);
  1250. SER_PUSH_uint16(&p_struct->max_rx_time_us);
  1251. SER_STRUCT_ENC_END;
  1252. }
  1253. uint32_t ble_gap_data_length_params_t_dec(uint8_t const * const p_buf,
  1254. uint32_t buf_len,
  1255. uint32_t * const p_index,
  1256. void * const p_void_struct)
  1257. {
  1258. SER_STRUCT_DEC_BEGIN(ble_gap_data_length_params_t);
  1259. SER_PULL_uint16(&p_struct->max_tx_octets);
  1260. SER_PULL_uint16(&p_struct->max_rx_octets);
  1261. SER_PULL_uint16(&p_struct->max_tx_time_us);
  1262. SER_PULL_uint16(&p_struct->max_rx_time_us);
  1263. SER_STRUCT_DEC_END;
  1264. }
  1265. uint32_t ble_gap_data_length_limitation_t_enc(void const * const p_void_struct,
  1266. uint8_t * const p_buf,
  1267. uint32_t buf_len,
  1268. uint32_t * const p_index)
  1269. {
  1270. SER_STRUCT_ENC_BEGIN(ble_gap_data_length_limitation_t);
  1271. SER_PUSH_uint16(&p_struct->tx_payload_limited_octets);
  1272. SER_PUSH_uint16(&p_struct->rx_payload_limited_octets);
  1273. SER_PUSH_uint16(&p_struct->tx_rx_time_limited_us);
  1274. SER_STRUCT_ENC_END;
  1275. }
  1276. uint32_t ble_gap_data_length_limitation_t_dec(uint8_t const * const p_buf,
  1277. uint32_t buf_len,
  1278. uint32_t * const p_index,
  1279. void * const p_void_struct)
  1280. {
  1281. SER_STRUCT_DEC_BEGIN(ble_gap_data_length_limitation_t);
  1282. SER_PULL_uint16(&p_struct->tx_payload_limited_octets);
  1283. SER_PULL_uint16(&p_struct->rx_payload_limited_octets);
  1284. SER_PULL_uint16(&p_struct->tx_rx_time_limited_us);
  1285. SER_STRUCT_DEC_END;
  1286. }
  1287. #endif //!S112
  1288. #endif
  1289. #if NRF_SD_BLE_API_VERSION == 4
  1290. uint32_t ble_gap_opt_compat_mode_2_t_enc(void const * const p_void_struct,
  1291. uint8_t * const p_buf,
  1292. uint32_t buf_len,
  1293. uint32_t * const p_index)
  1294. {
  1295. SER_STRUCT_ENC_BEGIN(ble_gap_opt_compat_mode_2_t);
  1296. uint8_t enable = p_struct->enable;
  1297. SER_PUSH_uint8(&enable);
  1298. SER_STRUCT_ENC_END;
  1299. }
  1300. uint32_t ble_gap_opt_compat_mode_2_t_dec(uint8_t const * const p_buf,
  1301. uint32_t buf_len,
  1302. uint32_t * const p_index,
  1303. void * const p_void_struct)
  1304. {
  1305. SER_STRUCT_DEC_BEGIN(ble_gap_opt_compat_mode_2_t);
  1306. uint8_t enable;
  1307. SER_PULL_uint8(&enable);
  1308. p_struct->enable = enable;
  1309. SER_STRUCT_DEC_END;
  1310. }
  1311. #endif
  1312. #if NRF_SD_BLE_API_VERSION >= 5
  1313. uint32_t ble_gap_phys_t_enc(void const * const p_void_struct,
  1314. uint8_t * const p_buf,
  1315. uint32_t buf_len,
  1316. uint32_t * const p_index)
  1317. {
  1318. SER_STRUCT_ENC_BEGIN(ble_gap_phys_t);
  1319. SER_PUSH_uint8(&p_struct->tx_phys);
  1320. SER_PUSH_uint8(&p_struct->rx_phys);
  1321. SER_STRUCT_ENC_END;
  1322. }
  1323. uint32_t ble_gap_phys_t_dec(uint8_t const * const p_buf,
  1324. uint32_t buf_len,
  1325. uint32_t * const p_index,
  1326. void * const p_void_struct)
  1327. {
  1328. SER_STRUCT_DEC_BEGIN(ble_gap_phys_t);
  1329. SER_PULL_uint8(&p_struct->tx_phys);
  1330. SER_PULL_uint8(&p_struct->rx_phys);
  1331. SER_STRUCT_DEC_END;
  1332. }
  1333. #endif
  1334. #if NRF_SD_BLE_API_VERSION > 5
  1335. uint32_t ble_gap_adv_properties_t_enc(void const * const p_void_struct,
  1336. uint8_t * const p_buf,
  1337. uint32_t buf_len,
  1338. uint32_t * const p_index)
  1339. {
  1340. SER_STRUCT_ENC_BEGIN(ble_gap_adv_properties_t);
  1341. SER_PUSH_uint8(&p_struct->type);
  1342. uint8_t temp = p_struct->anonymous | (p_struct->include_tx_power << 1);
  1343. SER_PUSH_uint8(&temp);
  1344. SER_STRUCT_ENC_END;
  1345. }
  1346. uint32_t ble_gap_adv_properties_t_dec(uint8_t const * const p_buf,
  1347. uint32_t buf_len,
  1348. uint32_t * const p_index,
  1349. void * const p_void_struct)
  1350. {
  1351. SER_STRUCT_DEC_BEGIN(ble_gap_adv_properties_t);
  1352. SER_PULL_uint8(&p_struct->type);
  1353. uint8_t temp;
  1354. SER_PULL_uint8(&temp);
  1355. p_struct->anonymous = temp & 0x01;
  1356. p_struct->include_tx_power = (temp & 0x02) ? 1 : 0;
  1357. SER_STRUCT_DEC_END;
  1358. }
  1359. #ifndef S112
  1360. uint32_t ble_gap_adv_report_type_t_enc(void const * const p_void_struct,
  1361. uint8_t * const p_buf,
  1362. uint32_t buf_len,
  1363. uint32_t * const p_index)
  1364. {
  1365. SER_STRUCT_ENC_BEGIN(ble_gap_adv_report_type_t);
  1366. uint16_t temp =
  1367. (p_struct->connectable << 0) |
  1368. (p_struct->scannable << 1) |
  1369. (p_struct->directed << 2) |
  1370. (p_struct->scan_response << 3) |
  1371. (p_struct->extended_pdu << 4) |
  1372. (p_struct->status << 5) |
  1373. (p_struct->reserved << 7);
  1374. SER_PUSH_uint16(&temp);
  1375. SER_STRUCT_ENC_END;
  1376. }
  1377. uint32_t ble_gap_adv_report_type_t_dec(uint8_t const * const p_buf,
  1378. uint32_t buf_len,
  1379. uint32_t * const p_index,
  1380. void * const p_void_struct)
  1381. {
  1382. SER_STRUCT_DEC_BEGIN(ble_gap_adv_report_type_t);
  1383. uint16_t temp;
  1384. SER_PULL_uint16(&temp);
  1385. p_struct->connectable = (temp >> 0) & 0x01;
  1386. p_struct->scannable = (temp >> 1) & 0x01;
  1387. p_struct->directed = (temp >> 2) & 0x01;
  1388. p_struct->scan_response = (temp >> 3) & 0x01;
  1389. p_struct->extended_pdu = (temp >> 4) & 0x01;
  1390. p_struct->status = (temp >> 5) & 0x03;
  1391. p_struct->reserved = (temp >> 7) & 0x1FF;
  1392. SER_STRUCT_DEC_END;
  1393. }
  1394. uint32_t ble_gap_aux_pointer_t_enc(void const * const p_void_struct,
  1395. uint8_t * const p_buf,
  1396. uint32_t buf_len,
  1397. uint32_t * const p_index)
  1398. {
  1399. SER_STRUCT_ENC_BEGIN(ble_gap_aux_pointer_t);
  1400. SER_PUSH_uint16(&p_struct->aux_offset);
  1401. SER_PUSH_uint8(&p_struct->aux_phy);
  1402. SER_STRUCT_ENC_END;
  1403. }
  1404. uint32_t ble_gap_aux_pointer_t_dec(uint8_t const * const p_buf,
  1405. uint32_t buf_len,
  1406. uint32_t * const p_index,
  1407. void * const p_void_struct)
  1408. {
  1409. SER_STRUCT_DEC_BEGIN(ble_gap_aux_pointer_t);
  1410. SER_PULL_uint16(&p_struct->aux_offset);
  1411. SER_PULL_uint8(&p_struct->aux_phy);
  1412. SER_STRUCT_DEC_END;
  1413. }
  1414. #endif //!S112
  1415. uint32_t ble_gap_adv_data_t_enc(void const * const p_void_struct,
  1416. uint8_t * const p_buf,
  1417. uint32_t buf_len,
  1418. uint32_t * const p_index)
  1419. {
  1420. SER_STRUCT_ENC_BEGIN(ble_gap_adv_data_t);
  1421. SER_PUSH_FIELD(&p_struct->adv_data, ble_data_t_enc);
  1422. SER_PUSH_FIELD(&p_struct->scan_rsp_data, ble_data_t_enc);
  1423. SER_STRUCT_ENC_END;
  1424. }
  1425. uint32_t ble_gap_adv_data_t_dec(uint8_t const * const p_buf,
  1426. uint32_t buf_len,
  1427. uint32_t * const p_index,
  1428. void * const p_void_struct)
  1429. {
  1430. SER_STRUCT_DEC_BEGIN(ble_gap_adv_data_t);
  1431. SER_PULL_FIELD(&p_struct->adv_data, ble_data_t_dec);
  1432. SER_PULL_FIELD(&p_struct->scan_rsp_data, ble_data_t_dec);
  1433. SER_STRUCT_DEC_END;
  1434. }
  1435. uint32_t ble_gap_evt_adv_set_terminated_t_enc(void const * const p_void_struct,
  1436. uint8_t * const p_buf,
  1437. uint32_t buf_len,
  1438. uint32_t * const p_index)
  1439. {
  1440. SER_STRUCT_ENC_BEGIN(ble_gap_evt_adv_set_terminated_t);
  1441. SER_PUSH_uint8(&p_struct->reason);
  1442. SER_PUSH_uint8(&p_struct->adv_handle);
  1443. SER_PUSH_uint8(&p_struct->num_completed_adv_events);
  1444. SER_PUSH_FIELD(&p_struct->adv_data, ble_gap_adv_data_t_enc);
  1445. SER_STRUCT_ENC_END;
  1446. }
  1447. uint32_t ble_gap_evt_adv_set_terminated_t_dec(uint8_t const * const p_buf,
  1448. uint32_t buf_len,
  1449. uint32_t * const p_index,
  1450. void * const p_void_struct)
  1451. {
  1452. SER_STRUCT_DEC_BEGIN(ble_gap_evt_adv_set_terminated_t);
  1453. SER_PULL_uint8(&p_struct->reason);
  1454. SER_PULL_uint8(&p_struct->adv_handle);
  1455. SER_PULL_uint8(&p_struct->num_completed_adv_events);
  1456. SER_PULL_FIELD(&p_struct->adv_data, ble_gap_adv_data_t_dec);
  1457. SER_STRUCT_DEC_END;
  1458. }
  1459. #endif