ble_gattc_struct_serialization.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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_gatt_struct_serialization.h"
  41. #include "ble_gattc_struct_serialization.h"
  42. #include "ble_struct_serialization.h"
  43. #include "ble_serialization.h"
  44. #include "app_util.h"
  45. #include "ble_gattc.h"
  46. #include "cond_field_serialization.h"
  47. #include <string.h>
  48. uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_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_gattc_evt_char_val_by_uuid_read_rsp_t);
  54. SER_PUSH_uint16(&p_struct->count);
  55. SER_PUSH_uint16(&p_struct->value_len);
  56. // Copy the whole packed list.
  57. uint16_t list_length = (p_struct->value_len + sizeof(uint16_t)) * p_struct->count;
  58. SER_PUSH_uint8array(p_struct->handle_value, list_length);
  59. SER_STRUCT_ENC_END;
  60. }
  61. uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_t_dec(uint8_t const * const p_buf,
  62. uint32_t buf_len,
  63. uint32_t * const p_index,
  64. uint32_t * const p_ext_len,
  65. void * const p_void_struct)
  66. {
  67. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_char_val_by_uuid_read_rsp_t);
  68. SER_PULL_uint16(&p_struct->count);
  69. SER_PULL_uint16(&p_struct->value_len);
  70. uint16_t list_length = (p_struct->value_len + sizeof(uint16_t)) * p_struct->count;
  71. SER_ASSERT_LENGTH_LEQ(list_length, *p_ext_len);
  72. SER_PULL_uint8array(p_struct->handle_value, list_length);
  73. *p_ext_len = list_length;
  74. SER_STRUCT_DEC_END;
  75. }
  76. uint32_t ble_gattc_evt_char_vals_read_rsp_t_enc(void const * const p_void_struct,
  77. uint8_t * const p_buf,
  78. uint32_t buf_len,
  79. uint32_t * const p_index)
  80. {
  81. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_char_vals_read_rsp_t);
  82. SER_PUSH_uint16(&p_struct->len);
  83. SER_PUSH_uint8array(p_struct->values, p_struct->len);
  84. SER_STRUCT_ENC_END;
  85. }
  86. uint32_t ble_gattc_evt_char_vals_read_rsp_t_dec(uint8_t const * const p_buf,
  87. uint32_t buf_len,
  88. uint32_t * const p_index,
  89. uint32_t * const p_ext_len,
  90. void * const p_void_struct)
  91. {
  92. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_char_vals_read_rsp_t);
  93. SER_PULL_uint16(&p_struct->len);
  94. SER_ASSERT_LENGTH_LEQ(p_struct->len, *p_ext_len);
  95. SER_PULL_uint8array(p_struct->values, p_struct->len);
  96. *p_ext_len = p_struct->len;
  97. SER_STRUCT_DEC_END;
  98. }
  99. uint32_t ble_gattc_handle_range_t_enc(void const * const p_void_struct,
  100. uint8_t * const p_buf,
  101. uint32_t buf_len,
  102. uint32_t * const p_index)
  103. {
  104. SER_STRUCT_ENC_BEGIN(ble_gattc_handle_range_t);
  105. SER_PUSH_uint16(&p_struct->start_handle);
  106. SER_PUSH_uint16(&p_struct->end_handle);
  107. SER_STRUCT_ENC_END;
  108. }
  109. uint32_t ble_gattc_handle_range_t_dec(uint8_t const * const p_buf,
  110. uint32_t buf_len,
  111. uint32_t * const p_index,
  112. void * const p_void_struct)
  113. {
  114. SER_STRUCT_DEC_BEGIN(ble_gattc_handle_range_t);
  115. SER_PULL_uint16(&p_struct->start_handle);
  116. SER_PULL_uint16(&p_struct->end_handle);
  117. SER_STRUCT_DEC_END;
  118. }
  119. uint32_t ble_gattc_service_t_enc(void const * const p_void_struct,
  120. uint8_t * const p_buf,
  121. uint32_t buf_len,
  122. uint32_t * const p_index)
  123. {
  124. SER_STRUCT_ENC_BEGIN(ble_gattc_service_t);
  125. SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc);
  126. SER_PUSH_FIELD(&p_struct->handle_range, ble_gattc_handle_range_t_enc);
  127. SER_STRUCT_ENC_END;
  128. }
  129. uint32_t ble_gattc_service_t_dec(uint8_t const * const p_buf,
  130. uint32_t buf_len,
  131. uint32_t * const p_index,
  132. void * const p_void_struct)
  133. {
  134. SER_STRUCT_DEC_BEGIN(ble_gattc_service_t);
  135. SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec);
  136. SER_PULL_FIELD(&p_struct->handle_range, ble_gattc_handle_range_t_dec);
  137. SER_STRUCT_DEC_END;
  138. }
  139. uint32_t ble_gattc_include_t_enc(void const * const p_void_struct,
  140. uint8_t * const p_buf,
  141. uint32_t buf_len,
  142. uint32_t * const p_index)
  143. {
  144. SER_STRUCT_ENC_BEGIN(ble_gattc_include_t);
  145. SER_PUSH_uint16(&p_struct->handle);
  146. SER_PUSH_FIELD(&p_struct->included_srvc, ble_gattc_service_t_enc);
  147. SER_STRUCT_ENC_END;
  148. }
  149. uint32_t ble_gattc_include_t_dec(uint8_t const * const p_buf,
  150. uint32_t buf_len,
  151. uint32_t * const p_index,
  152. void * const p_void_struct)
  153. {
  154. SER_STRUCT_DEC_BEGIN(ble_gattc_include_t);
  155. SER_PULL_uint16(&p_struct->handle);
  156. SER_PULL_FIELD(&p_struct->included_srvc, ble_gattc_service_t_dec);
  157. SER_STRUCT_DEC_END;
  158. }
  159. uint32_t ble_gattc_evt_rel_disc_rsp_t_enc(void const * const p_void_struct,
  160. uint8_t * const p_buf,
  161. uint32_t buf_len,
  162. uint32_t * const p_index)
  163. {
  164. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_rel_disc_rsp_t);
  165. SER_PUSH_uint16(&p_struct->count);
  166. ble_gattc_include_t * p_include = &(p_struct->includes[0]);
  167. uint32_t i;
  168. for (i = 0; i < p_struct->count; i++)
  169. {
  170. SER_PUSH_FIELD(p_include, ble_gattc_include_t_enc);
  171. ++p_include;
  172. }
  173. SER_STRUCT_ENC_END;
  174. }
  175. uint32_t ble_gattc_evt_rel_disc_rsp_t_dec(uint8_t const * const p_buf,
  176. uint32_t buf_len,
  177. uint32_t * const p_index,
  178. uint32_t * const p_ext_len,
  179. void * const p_void_struct)
  180. {
  181. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_rel_disc_rsp_t);
  182. SER_PULL_uint16(&p_struct->count);
  183. uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_include_t));
  184. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  185. ble_gattc_include_t * p_include = &(p_struct->includes[0]);
  186. uint32_t i;
  187. for (i = 0; i < p_struct->count; i++)
  188. {
  189. SER_PULL_FIELD(p_include, ble_gattc_include_t_dec);
  190. ++p_include;
  191. }
  192. *p_ext_len = data_len;
  193. SER_STRUCT_DEC_END;
  194. }
  195. uint32_t ble_gattc_write_params_t_enc(void const * const p_void_struct,
  196. uint8_t * const p_buf,
  197. uint32_t buf_len,
  198. uint32_t * const p_index)
  199. {
  200. SER_STRUCT_ENC_BEGIN(ble_gattc_write_params_t);
  201. SER_PUSH_uint8(&p_struct->write_op);
  202. SER_PUSH_uint8(&p_struct->flags);
  203. SER_PUSH_uint16(&p_struct->handle);
  204. SER_PUSH_uint16(&p_struct->offset);
  205. SER_PUSH_len16data(p_struct->p_value, p_struct->len);
  206. SER_STRUCT_ENC_END;
  207. }
  208. uint32_t ble_gattc_write_params_t_dec(uint8_t const * const p_buf,
  209. uint32_t buf_len,
  210. uint32_t * const p_index,
  211. void * const p_void_struct)
  212. {
  213. SER_STRUCT_DEC_BEGIN(ble_gattc_write_params_t);
  214. SER_PULL_uint8(&p_struct->write_op);
  215. SER_PULL_uint8(&p_struct->flags);
  216. SER_PULL_uint16(&p_struct->handle);
  217. SER_PULL_uint16(&p_struct->offset);
  218. SER_PULL_len16data((uint8_t **) &p_struct->p_value, &p_struct->len);
  219. SER_STRUCT_DEC_END;
  220. }
  221. uint32_t ble_gattc_attr_info16_t_enc(void const * const p_void_struct,
  222. uint8_t * const p_buf,
  223. uint32_t buf_len,
  224. uint32_t * const p_index)
  225. {
  226. SER_STRUCT_ENC_BEGIN(ble_gattc_attr_info16_t);
  227. SER_PUSH_uint16(&p_struct->handle);
  228. SER_PUSH_FIELD(&(p_struct->uuid), ble_uuid_t_enc);
  229. SER_STRUCT_ENC_END;
  230. }
  231. uint32_t ble_gattc_attr_info16_t_dec(uint8_t const * const p_buf,
  232. uint32_t buf_len,
  233. uint32_t * const p_index,
  234. void * const p_void_struct)
  235. {
  236. SER_STRUCT_DEC_BEGIN(ble_gattc_attr_info16_t);
  237. SER_PULL_uint16(&p_struct->handle);
  238. SER_PULL_FIELD(&(p_struct->uuid), ble_uuid_t_dec);
  239. SER_STRUCT_DEC_END;
  240. }
  241. uint32_t ble_gattc_attr_info128_t_enc(void const * const p_void_struct,
  242. uint8_t * const p_buf,
  243. uint32_t buf_len,
  244. uint32_t * const p_index)
  245. {
  246. SER_STRUCT_ENC_BEGIN(ble_gattc_attr_info128_t);
  247. SER_PUSH_uint16(&p_struct->handle);
  248. SER_PUSH_FIELD(&(p_struct->uuid), ble_uuid128_t_enc);
  249. SER_STRUCT_ENC_END;
  250. }
  251. uint32_t ble_gattc_attr_info128_t_dec(uint8_t const * const p_buf,
  252. uint32_t buf_len,
  253. uint32_t * const p_index,
  254. void * const p_void_struct)
  255. {
  256. SER_STRUCT_DEC_BEGIN(ble_gattc_attr_info128_t);
  257. SER_PULL_uint16(&p_struct->handle);
  258. SER_PULL_FIELD(&(p_struct->uuid), ble_uuid128_t_dec);
  259. SER_STRUCT_DEC_END;
  260. }
  261. uint32_t ble_gattc_evt_attr_info_disc_rsp_t_enc(void const * const p_void_struct,
  262. uint8_t * const p_buf,
  263. uint32_t buf_len,
  264. uint32_t * const p_index)
  265. {
  266. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_attr_info_disc_rsp_t);
  267. SER_PUSH_uint16(&p_struct->count);
  268. SER_PUSH_uint8(&p_struct->format);
  269. field_encoder_handler_t fp_encoder = (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) ?
  270. ble_gattc_attr_info16_t_enc : ble_gattc_attr_info128_t_enc;
  271. uint32_t i;
  272. for (i = 0; i < p_struct->count; ++i)
  273. {
  274. void * uuid_struct;
  275. uuid_struct = (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) ?
  276. (void *)&(p_struct->info.attr_info16[i]) : (void *)&(p_struct->info.attr_info128[i]);
  277. SER_PUSH_FIELD(uuid_struct, fp_encoder);
  278. }
  279. SER_STRUCT_ENC_END;
  280. }
  281. uint32_t ble_gattc_evt_attr_info_disc_rsp_t_dec(uint8_t const * const p_buf,
  282. uint32_t buf_len,
  283. uint32_t * const p_index,
  284. uint32_t * const p_ext_len,
  285. void * const p_void_struct)
  286. {
  287. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_attr_info_disc_rsp_t);
  288. SER_PULL_uint16(&p_struct->count);
  289. SER_PULL_uint8(&p_struct->format);
  290. uint32_t i;
  291. uint32_t data_len;
  292. field_decoder_handler_t fp_decoder;
  293. if (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT)
  294. {
  295. fp_decoder = ble_gattc_attr_info16_t_dec;
  296. data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_attr_info16_t));
  297. }
  298. else
  299. {
  300. fp_decoder = ble_gattc_attr_info128_t_dec;
  301. data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_attr_info128_t));
  302. }
  303. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  304. for (i = 0; i < p_struct->count; i++)
  305. {
  306. void * uuid_struct;
  307. uuid_struct = (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) ?
  308. (void *)&(p_struct->info.attr_info16[i]) : (void *)&(p_struct->info.attr_info128[i]);
  309. SER_PULL_FIELD(uuid_struct, fp_decoder);
  310. }
  311. *p_ext_len = data_len;
  312. SER_STRUCT_DEC_END;
  313. }
  314. uint32_t ble_gattc_char_t_enc(void const * const p_void_struct,
  315. uint8_t * const p_buf,
  316. uint32_t buf_len,
  317. uint32_t * const p_index)
  318. {
  319. SER_STRUCT_ENC_BEGIN(ble_gattc_char_t);
  320. uint8_t ser_data;
  321. SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc);
  322. SER_PUSH_FIELD(&p_struct->char_props, ble_gatt_char_props_t_enc);
  323. ser_data = p_struct->char_ext_props & 0x01;
  324. SER_PUSH_uint8(&ser_data);
  325. SER_PUSH_uint16(&p_struct->handle_decl);
  326. SER_PUSH_uint16(&p_struct->handle_value);
  327. SER_STRUCT_ENC_END;
  328. }
  329. uint32_t ble_gattc_char_t_dec(uint8_t const * const p_buf,
  330. uint32_t buf_len,
  331. uint32_t * const p_index,
  332. void * const p_void_struct)
  333. {
  334. SER_STRUCT_DEC_BEGIN(ble_gattc_char_t);
  335. uint8_t ser_data;
  336. SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec);
  337. SER_PULL_FIELD(&p_struct->char_props, ble_gatt_char_props_t_dec);
  338. SER_PULL_uint8(&ser_data);
  339. p_struct->char_ext_props = ser_data & 0x01;
  340. SER_PULL_uint16(&p_struct->handle_decl);
  341. SER_PULL_uint16(&p_struct->handle_value);
  342. SER_STRUCT_DEC_END;
  343. }
  344. uint32_t ble_gattc_evt_char_disc_rsp_t_enc(void const * const p_void_struct,
  345. uint8_t * const p_buf,
  346. uint32_t buf_len,
  347. uint32_t * const p_index)
  348. {
  349. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_char_disc_rsp_t);
  350. SER_PUSH_uint16(&p_struct->count);
  351. SER_PUSH_FIELD_ARRAY(p_struct->chars, ble_gattc_char_t_enc, p_struct->count);
  352. SER_STRUCT_ENC_END;
  353. }
  354. uint32_t ble_gattc_evt_char_disc_rsp_t_dec(uint8_t const * const p_buf,
  355. uint32_t buf_len,
  356. uint32_t * const p_index,
  357. uint32_t * const p_ext_len,
  358. void * const p_void_struct)
  359. {
  360. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_char_disc_rsp_t);
  361. SER_PULL_uint16(&p_struct->count);
  362. uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_char_t));
  363. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  364. SER_PULL_FIELD_ARRAY(p_struct->chars, ble_gattc_char_t_dec, p_struct->count);
  365. *p_ext_len = data_len;
  366. SER_STRUCT_DEC_END;
  367. }
  368. uint32_t ble_gattc_desc_t_enc(void const * const p_void_struct,
  369. uint8_t * const p_buf,
  370. uint32_t buf_len,
  371. uint32_t * const p_index)
  372. {
  373. SER_STRUCT_ENC_BEGIN(ble_gattc_desc_t);
  374. SER_PUSH_uint16(&p_struct->handle);
  375. SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc);
  376. SER_STRUCT_ENC_END;
  377. }
  378. uint32_t ble_gattc_desc_t_dec(uint8_t const * const p_buf,
  379. uint32_t buf_len,
  380. uint32_t * const p_index,
  381. void * const p_void_struct)
  382. {
  383. SER_STRUCT_DEC_BEGIN(ble_gattc_desc_t);
  384. SER_PULL_uint16(&p_struct->handle);
  385. SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec);
  386. SER_STRUCT_DEC_END;
  387. }
  388. uint32_t ble_gattc_evt_desc_disc_rsp_t_enc(void const * const p_void_struct,
  389. uint8_t * const p_buf,
  390. uint32_t buf_len,
  391. uint32_t * const p_index)
  392. {
  393. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_desc_disc_rsp_t);
  394. SER_PUSH_uint16(&p_struct->count);
  395. SER_PUSH_FIELD_ARRAY(p_struct->descs, ble_gattc_desc_t_enc, p_struct->count);
  396. SER_STRUCT_ENC_END;
  397. }
  398. uint32_t ble_gattc_evt_desc_disc_rsp_t_dec(uint8_t const * const p_buf,
  399. uint32_t buf_len,
  400. uint32_t * const p_index,
  401. uint32_t * const p_ext_len,
  402. void * const p_void_struct)
  403. {
  404. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_desc_disc_rsp_t);
  405. SER_PULL_uint16(&p_struct->count);
  406. uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_desc_t));
  407. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  408. SER_PULL_FIELD_ARRAY(p_struct->descs, ble_gattc_desc_t_dec, p_struct->count);
  409. *p_ext_len = data_len;
  410. SER_STRUCT_DEC_END;
  411. }
  412. uint32_t ble_gattc_evt_hvx_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_gattc_evt_hvx_t);
  418. SER_PUSH_uint16(&p_struct->handle);
  419. SER_PUSH_uint8(&p_struct->type);
  420. SER_PUSH_uint16(&p_struct->len);
  421. SER_PUSH_uint8array(p_struct->data, p_struct->len);
  422. SER_STRUCT_ENC_END;
  423. }
  424. uint32_t ble_gattc_evt_hvx_t_dec(uint8_t const * const p_buf,
  425. uint32_t buf_len,
  426. uint32_t * const p_index,
  427. uint32_t * const p_ext_len,
  428. void * const p_void_struct)
  429. {
  430. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_hvx_t);
  431. SER_PULL_uint16(&p_struct->handle);
  432. SER_PULL_uint8(&p_struct->type);
  433. SER_PULL_uint16(&p_struct->len);
  434. uint32_t data_len = (SUB1(p_struct->len));
  435. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  436. SER_PULL_uint8array(p_struct->data, p_struct->len);
  437. *p_ext_len = data_len;
  438. SER_STRUCT_DEC_END;
  439. }
  440. uint32_t ble_gattc_evt_prim_srvc_disc_rsp_t_enc(void const * const p_void_struct,
  441. uint8_t * const p_buf,
  442. uint32_t buf_len,
  443. uint32_t * const p_index)
  444. {
  445. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_prim_srvc_disc_rsp_t);
  446. SER_PUSH_uint16(&p_struct->count);
  447. SER_PUSH_FIELD_ARRAY(p_struct->services, ble_gattc_service_t_enc, p_struct->count);
  448. SER_STRUCT_ENC_END;
  449. }
  450. uint32_t ble_gattc_evt_prim_srvc_disc_rsp_t_dec(uint8_t const * const p_buf,
  451. uint32_t buf_len,
  452. uint32_t * const p_index,
  453. uint32_t * const p_ext_len,
  454. void * const p_void_struct)
  455. {
  456. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_prim_srvc_disc_rsp_t);
  457. SER_PULL_uint16(&p_struct->count);
  458. uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_service_t));
  459. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  460. SER_PULL_FIELD_ARRAY(p_struct->services, ble_gattc_service_t_dec, p_struct->count);
  461. *p_ext_len = data_len;
  462. SER_STRUCT_DEC_END;
  463. }
  464. uint32_t ble_gattc_evt_read_rsp_t_enc(void const * const p_void_struct,
  465. uint8_t * const p_buf,
  466. uint32_t buf_len,
  467. uint32_t * const p_index)
  468. {
  469. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_read_rsp_t);
  470. SER_PUSH_uint16(&p_struct->handle);
  471. SER_PUSH_uint16(&p_struct->offset);
  472. SER_PUSH_uint16(&p_struct->len);
  473. SER_PUSH_uint8array(p_struct->data, p_struct->len);
  474. SER_STRUCT_ENC_END;
  475. }
  476. uint32_t ble_gattc_evt_read_rsp_t_dec(uint8_t const * const p_buf,
  477. uint32_t buf_len,
  478. uint32_t * const p_index,
  479. uint32_t * const p_ext_len,
  480. void * const p_void_struct)
  481. {
  482. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_read_rsp_t);
  483. SER_PULL_uint16(&p_struct->handle);
  484. SER_PULL_uint16(&p_struct->offset);
  485. SER_PULL_uint16(&p_struct->len);
  486. uint32_t data_len = (SUB1(p_struct->len));
  487. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  488. SER_PULL_uint8array(p_struct->data, p_struct->len);
  489. *p_ext_len = data_len;
  490. SER_STRUCT_DEC_END;
  491. }
  492. uint32_t ble_gattc_evt_timeout_t_enc(void const * const p_void_struct,
  493. uint8_t * const p_buf,
  494. uint32_t buf_len,
  495. uint32_t * const p_index)
  496. {
  497. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_timeout_t);
  498. SER_PUSH_uint8(&p_struct->src);
  499. SER_STRUCT_ENC_END;
  500. }
  501. uint32_t ble_gattc_evt_timeout_t_dec(uint8_t const * const p_buf,
  502. uint32_t buf_len,
  503. uint32_t * const p_index,
  504. void * const p_void_struct)
  505. {
  506. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_timeout_t);
  507. SER_PULL_uint8(&p_struct->src);
  508. SER_STRUCT_DEC_END;
  509. }
  510. uint32_t ble_gattc_evt_write_rsp_t_enc(void const * const p_void_struct,
  511. uint8_t * const p_buf,
  512. uint32_t buf_len,
  513. uint32_t * const p_index)
  514. {
  515. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_write_rsp_t);
  516. SER_PUSH_uint16(&p_struct->handle);
  517. SER_PUSH_uint8(&p_struct->write_op);
  518. SER_PUSH_uint16(&p_struct->offset);
  519. SER_PUSH_uint16(&p_struct->len);
  520. SER_PUSH_uint8array(p_struct->data, p_struct->len);
  521. SER_STRUCT_ENC_END;
  522. }
  523. uint32_t ble_gattc_evt_write_rsp_t_dec(uint8_t const * const p_buf,
  524. uint32_t buf_len,
  525. uint32_t * const p_index,
  526. uint32_t * const p_ext_len,
  527. void * const p_void_struct)
  528. {
  529. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_write_rsp_t);
  530. SER_PULL_uint16(&p_struct->handle);
  531. SER_PULL_uint8(&p_struct->write_op);
  532. SER_PULL_uint16(&p_struct->offset);
  533. SER_PULL_uint16(&p_struct->len);
  534. uint32_t data_len = (SUB1(p_struct->len));
  535. SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len);
  536. SER_PULL_uint8array(p_struct->data, p_struct->len);
  537. *p_ext_len = data_len;
  538. SER_STRUCT_DEC_END;
  539. }
  540. uint32_t ble_gattc_evt_exchange_mtu_rsp_t_enc(void const * const p_void_struct,
  541. uint8_t * const p_buf,
  542. uint32_t buf_len,
  543. uint32_t * const p_index)
  544. {
  545. SER_STRUCT_ENC_BEGIN(ble_gattc_evt_exchange_mtu_rsp_t);
  546. SER_PUSH_uint16(&p_struct->server_rx_mtu);
  547. SER_STRUCT_ENC_END;
  548. }
  549. uint32_t ble_gattc_evt_exchange_mtu_rsp_t_dec(uint8_t const * const p_buf,
  550. uint32_t buf_len,
  551. uint32_t * const p_index,
  552. void * const p_void_struct)
  553. {
  554. SER_STRUCT_DEC_BEGIN(ble_gattc_evt_exchange_mtu_rsp_t);
  555. SER_PULL_uint16(&p_struct->server_rx_mtu);
  556. SER_STRUCT_DEC_END;
  557. }
  558. #if NRF_SD_BLE_API_VERSION >= 4
  559. uint32_t ble_gattc_conn_cfg_t_enc(void const * const p_void_struct,
  560. uint8_t * const p_buf,
  561. uint32_t buf_len,
  562. uint32_t * const p_index)
  563. {
  564. SER_STRUCT_ENC_BEGIN(ble_gattc_conn_cfg_t);
  565. SER_PUSH_uint8(&p_struct->write_cmd_tx_queue_size);
  566. SER_STRUCT_ENC_END;
  567. }
  568. uint32_t ble_gattc_conn_cfg_t_dec(uint8_t const * const p_buf,
  569. uint32_t buf_len,
  570. uint32_t * const p_index,
  571. void * const p_void_struct)
  572. {
  573. SER_STRUCT_DEC_BEGIN(ble_gattc_conn_cfg_t);
  574. SER_PULL_uint8(&p_struct->write_cmd_tx_queue_size);
  575. SER_STRUCT_DEC_END;
  576. }
  577. #endif