ble_gatts_struct_serialization.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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_gatts_struct_serialization.h"
  42. #include "ble_gap_struct_serialization.h"
  43. #include "ble_struct_serialization.h"
  44. #include "ble_serialization.h"
  45. #include "app_util.h"
  46. #include "ble_gatts.h"
  47. #include "cond_field_serialization.h"
  48. #include <string.h>
  49. uint32_t ble_gatts_char_pf_t_enc(void const * const p_void_struct,
  50. uint8_t * const p_buf,
  51. uint32_t buf_len,
  52. uint32_t * const p_index)
  53. {
  54. SER_STRUCT_ENC_BEGIN(ble_gatts_char_pf_t);
  55. SER_PUSH_uint8(&p_struct->format);
  56. SER_PUSH_int8(&p_struct->exponent);
  57. SER_PUSH_uint16(&p_struct->unit);
  58. SER_PUSH_uint8(&p_struct->name_space);
  59. SER_PUSH_uint16(&p_struct->desc);
  60. SER_STRUCT_ENC_END;
  61. }
  62. uint32_t ble_gatts_char_pf_t_dec(uint8_t const * const p_buf,
  63. uint32_t buf_len,
  64. uint32_t * const p_index,
  65. void * const p_void_struct)
  66. {
  67. SER_STRUCT_DEC_BEGIN(ble_gatts_char_pf_t);
  68. SER_PULL_uint8(&p_struct->format);
  69. SER_PULL_int8(&p_struct->exponent);
  70. SER_PULL_uint16(&p_struct->unit);
  71. SER_PULL_uint8(&p_struct->name_space);
  72. SER_PULL_uint16(&p_struct->desc);
  73. SER_STRUCT_DEC_END;
  74. }
  75. uint32_t ble_gatts_attr_md_t_enc(void const * const p_void_struct,
  76. uint8_t * const p_buf,
  77. uint32_t buf_len,
  78. uint32_t * const p_index)
  79. {
  80. SER_STRUCT_ENC_BEGIN(ble_gatts_attr_md_t);
  81. SER_PUSH_FIELD(&p_struct->read_perm, ble_gap_conn_sec_mode_t_enc);
  82. SER_PUSH_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_enc);
  83. uint8_t ser_data = (p_struct->vlen & 0x01)
  84. | ((p_struct->vloc & 0x03) << 1)
  85. | ((p_struct->rd_auth & 0x01) << 3)
  86. | ((p_struct->wr_auth & 0x01) << 4);
  87. SER_PUSH_uint8(&ser_data);
  88. // Serializer does not support attributes on stack.
  89. if (p_struct->vloc != BLE_GATTS_VLOC_STACK)
  90. {
  91. err_code = NRF_ERROR_INVALID_PARAM;
  92. }
  93. SER_STRUCT_ENC_END;
  94. }
  95. uint32_t ble_gatts_attr_md_t_dec(uint8_t const * const p_buf,
  96. uint32_t buf_len,
  97. uint32_t * const p_index,
  98. void * const p_void_struct)
  99. {
  100. SER_STRUCT_DEC_BEGIN(ble_gatts_attr_md_t);
  101. uint8_t ser_data;
  102. SER_PULL_FIELD(&p_struct->read_perm, ble_gap_conn_sec_mode_t_dec);
  103. SER_PULL_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_dec);
  104. SER_PULL_uint8(&ser_data);
  105. p_struct->vlen = ser_data & 0x01;
  106. p_struct->vloc = (ser_data >> 1) & 0x03;
  107. p_struct->rd_auth = (ser_data >> 3) & 0x01;
  108. p_struct->wr_auth = (ser_data >> 4) & 0x01;
  109. SER_STRUCT_DEC_END;
  110. }
  111. uint32_t ble_gatts_char_md_t_enc(void const * const p_void_struct,
  112. uint8_t * const p_buf,
  113. uint32_t buf_len,
  114. uint32_t * const p_index)
  115. {
  116. SER_STRUCT_ENC_BEGIN(ble_gatts_char_md_t);
  117. SER_PUSH_FIELD(&p_struct->char_props, ble_gatt_char_props_t_enc);
  118. SER_PUSH_FIELD(&p_struct->char_ext_props, ble_gatt_char_ext_props_t_enc);
  119. SER_PUSH_uint16(&p_struct->char_user_desc_max_size);
  120. SER_ERROR_CHECK(p_struct->char_user_desc_size <= BLE_GATTS_VAR_ATTR_LEN_MAX,
  121. NRF_ERROR_INVALID_PARAM);
  122. SER_PUSH_len16data(p_struct->p_char_user_desc, p_struct->char_user_desc_size);
  123. SER_PUSH_COND(p_struct->p_char_pf, ble_gatts_char_pf_t_enc);
  124. SER_PUSH_COND(p_struct->p_user_desc_md, ble_gatts_attr_md_t_enc);
  125. SER_PUSH_COND(p_struct->p_cccd_md, ble_gatts_attr_md_t_enc);
  126. SER_PUSH_COND(p_struct->p_sccd_md, ble_gatts_attr_md_t_enc);
  127. SER_STRUCT_ENC_END;
  128. }
  129. uint32_t ble_gatts_char_md_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_gatts_char_md_t);
  135. SER_PULL_FIELD(&p_struct->char_props, ble_gatt_char_props_t_dec);
  136. SER_PULL_FIELD(&p_struct->char_ext_props, ble_gatt_char_ext_props_t_dec);
  137. SER_PULL_uint16(&p_struct->char_user_desc_max_size);
  138. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  139. SER_PULL_len16data(&p_struct->p_char_user_desc, &p_struct->char_user_desc_size);
  140. #else
  141. SER_PULL_len16data((uint8_t * * )&p_struct->p_char_user_desc, &p_struct->char_user_desc_size);
  142. #endif
  143. SER_PULL_COND(&p_struct->p_char_pf, ble_gatts_char_pf_t_dec);
  144. SER_PULL_COND(&p_struct->p_user_desc_md, ble_gatts_attr_md_t_dec);
  145. SER_PULL_COND(&p_struct->p_cccd_md, ble_gatts_attr_md_t_dec);
  146. SER_PULL_COND(&p_struct->p_sccd_md, ble_gatts_attr_md_t_dec);
  147. SER_STRUCT_ENC_END;
  148. }
  149. uint32_t ble_gatts_attr_t_enc(void const * const p_void_struct,
  150. uint8_t * const p_buf,
  151. uint32_t buf_len,
  152. uint32_t * const p_index)
  153. {
  154. SER_STRUCT_ENC_BEGIN(ble_gatts_attr_t);
  155. SER_PUSH_COND(p_struct->p_uuid, ble_uuid_t_enc);
  156. SER_PUSH_COND(p_struct->p_attr_md, ble_gatts_attr_md_t_enc);
  157. SER_PUSH_uint16(&p_struct->init_offs);
  158. SER_PUSH_uint16(&p_struct->max_len);
  159. SER_ERROR_CHECK(p_struct->init_len <= BLE_GATTS_VAR_ATTR_LEN_MAX, NRF_ERROR_INVALID_PARAM);
  160. SER_PUSH_len16data(p_struct->p_value, p_struct->init_len);
  161. SER_STRUCT_ENC_END;
  162. }
  163. uint32_t ble_gatts_attr_t_dec(uint8_t const * const p_buf,
  164. uint32_t buf_len,
  165. uint32_t * const p_index,
  166. void * const p_void_struct)
  167. {
  168. SER_STRUCT_DEC_BEGIN(ble_gatts_attr_t);
  169. SER_PULL_COND(&p_struct->p_uuid, ble_uuid_t_dec);
  170. SER_PULL_COND(&p_struct->p_attr_md, ble_gatts_attr_md_t_dec);
  171. SER_PULL_uint16(&p_struct->init_offs);
  172. SER_PULL_uint16(&p_struct->max_len);
  173. SER_PULL_len16data(&p_struct->p_value, &p_struct->init_len);
  174. SER_STRUCT_DEC_END;
  175. }
  176. uint32_t ble_gatts_char_handles_t_enc(void const * const p_void_struct,
  177. uint8_t * const p_buf,
  178. uint32_t buf_len,
  179. uint32_t * const p_index)
  180. {
  181. SER_STRUCT_ENC_BEGIN(ble_gatts_char_handles_t);
  182. SER_PUSH_uint16(&p_struct->value_handle);
  183. SER_PUSH_uint16(&p_struct->user_desc_handle);
  184. SER_PUSH_uint16(&p_struct->cccd_handle);
  185. SER_PUSH_uint16(&p_struct->sccd_handle);
  186. SER_STRUCT_ENC_END;
  187. }
  188. uint32_t ble_gatts_char_handles_t_dec(uint8_t const * const p_buf,
  189. uint32_t buf_len,
  190. uint32_t * const p_index,
  191. void * const p_void_struct)
  192. {
  193. SER_STRUCT_DEC_BEGIN(ble_gatts_char_handles_t);
  194. SER_PULL_uint16(&p_struct->value_handle);
  195. SER_PULL_uint16(&p_struct->user_desc_handle);
  196. SER_PULL_uint16(&p_struct->cccd_handle);
  197. SER_PULL_uint16(&p_struct->sccd_handle);
  198. SER_STRUCT_DEC_END;
  199. }
  200. uint32_t ble_gatts_hvx_params_t_enc(void const * const p_void_struct,
  201. uint8_t * const p_buf,
  202. uint32_t buf_len,
  203. uint32_t * const p_index)
  204. {
  205. SER_STRUCT_ENC_BEGIN(ble_gatts_hvx_params_t);
  206. SER_PUSH_uint16(&p_struct->handle);
  207. SER_PUSH_uint8(&p_struct->type);
  208. SER_PUSH_uint16(&p_struct->offset);
  209. SER_PUSH_COND(p_struct->p_len, uint16_t_enc);
  210. if (p_struct->p_len)
  211. {
  212. SER_PUSH_buf(p_struct->p_data, *p_struct->p_len);
  213. }
  214. SER_STRUCT_ENC_END;
  215. }
  216. uint32_t ble_gatts_hvx_params_t_dec(uint8_t const * const p_buf,
  217. uint32_t buf_len,
  218. uint32_t * const p_index,
  219. void * const p_void_struct)
  220. {
  221. SER_STRUCT_DEC_BEGIN(ble_gatts_hvx_params_t);
  222. SER_PULL_uint16(&p_struct->handle);
  223. SER_PULL_uint8(&p_struct->type);
  224. SER_PULL_uint16(&p_struct->offset);
  225. SER_PULL_COND(&p_struct->p_len, uint16_t_dec);
  226. if (p_struct->p_len)
  227. {
  228. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  229. SER_PULL_buf(&p_struct->p_data, *p_struct->p_len, *p_struct->p_len);
  230. #else
  231. SER_PULL_buf((uint8_t**)&p_struct->p_data, *p_struct->p_len, *p_struct->p_len);
  232. #endif
  233. }
  234. SER_STRUCT_DEC_END;
  235. }
  236. uint32_t ble_gatts_evt_write_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_gatts_evt_write_t);
  242. SER_PUSH_uint16(&p_struct->handle);
  243. SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc);
  244. SER_PUSH_uint8(&p_struct->op);
  245. SER_PUSH_uint8(&p_struct->auth_required);
  246. SER_PUSH_uint16(&p_struct->offset);
  247. SER_PUSH_uint16(&p_struct->len);
  248. SER_PUSH_uint8array(p_struct->data, p_struct->len);
  249. SER_STRUCT_ENC_END;
  250. }
  251. uint32_t ble_gatts_evt_write_t_dec(uint8_t const * const p_buf,
  252. uint32_t buf_len,
  253. uint32_t * const p_index,
  254. uint32_t * const p_ext_len,
  255. void * const p_void_struct)
  256. {
  257. SER_STRUCT_DEC_BEGIN(ble_gatts_evt_write_t);
  258. SER_PULL_uint16(&p_struct->handle);
  259. SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec);
  260. SER_PULL_uint8(&p_struct->op);
  261. SER_PULL_uint8(&p_struct->auth_required);
  262. SER_PULL_uint16(&p_struct->offset);
  263. SER_PULL_uint16(&p_struct->len);
  264. // Data field is defined as 1-element array, so the first element
  265. // is always allocated in the structure.
  266. SER_ASSERT_LENGTH_LEQ(p_struct->len, *p_ext_len + 1);
  267. SER_PULL_uint8array(p_struct->data, p_struct->len);
  268. *p_ext_len = (p_struct->len > 1) ? p_struct->len - 1 : 0;
  269. SER_STRUCT_ENC_END;
  270. }
  271. uint32_t ble_gatts_evt_read_t_enc(void const * const p_void_struct,
  272. uint8_t * const p_buf,
  273. uint32_t buf_len,
  274. uint32_t * const p_index)
  275. {
  276. SER_STRUCT_ENC_BEGIN(ble_gatts_evt_read_t);
  277. SER_PUSH_uint16(&p_struct->handle);
  278. SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc);
  279. SER_PUSH_uint16(&p_struct->offset);
  280. SER_STRUCT_ENC_END;
  281. }
  282. uint32_t ble_gatts_evt_read_t_dec(uint8_t const * const p_buf,
  283. uint32_t buf_len,
  284. uint32_t * const p_index,
  285. void * const p_void_struct)
  286. {
  287. SER_STRUCT_DEC_BEGIN(ble_gatts_evt_read_t);
  288. SER_PULL_uint16(&p_struct->handle);
  289. SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec);
  290. SER_PULL_uint16(&p_struct->offset);
  291. SER_STRUCT_DEC_END;
  292. }
  293. uint32_t ble_gatts_evt_rw_authorize_request_t_enc(void const * const p_void_struct,
  294. uint8_t * const p_buf,
  295. uint32_t buf_len,
  296. uint32_t * const p_index)
  297. {
  298. SER_STRUCT_ENC_BEGIN(ble_gatts_evt_rw_authorize_request_t);
  299. SER_PUSH_uint8(&p_struct->type);
  300. switch (p_struct->type)
  301. {
  302. case BLE_GATTS_AUTHORIZE_TYPE_READ:
  303. SER_PUSH_FIELD(&p_struct->request.read, ble_gatts_evt_read_t_enc);
  304. break;
  305. case BLE_GATTS_AUTHORIZE_TYPE_WRITE:
  306. SER_PUSH_FIELD(&p_struct->request.write, ble_gatts_evt_write_t_enc);
  307. break;
  308. default:
  309. case BLE_GATTS_AUTHORIZE_TYPE_INVALID:
  310. err_code = NRF_ERROR_INVALID_PARAM;
  311. break;
  312. }
  313. SER_STRUCT_ENC_END;
  314. }
  315. uint32_t ble_gatts_evt_rw_authorize_request_t_dec(uint8_t const * const p_buf,
  316. uint32_t buf_len,
  317. uint32_t * const p_index,
  318. uint32_t * const p_ext_len,
  319. void * const p_void_struct)
  320. {
  321. SER_STRUCT_DEC_BEGIN(ble_gatts_evt_rw_authorize_request_t);
  322. SER_PULL_uint8(&p_struct->type);
  323. switch (p_struct->type)
  324. {
  325. case BLE_GATTS_AUTHORIZE_TYPE_READ:
  326. SER_PULL_FIELD(&p_struct->request.read, ble_gatts_evt_read_t_dec);
  327. break;
  328. case BLE_GATTS_AUTHORIZE_TYPE_WRITE:
  329. err_code = ble_gatts_evt_write_t_dec(p_buf,
  330. buf_len,
  331. p_index,
  332. p_ext_len,
  333. &p_struct->request.write);
  334. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  335. break;
  336. default:
  337. case BLE_GATTS_AUTHORIZE_TYPE_INVALID:
  338. return NRF_ERROR_INVALID_DATA;
  339. }
  340. SER_STRUCT_ENC_END;
  341. }
  342. uint32_t ble_gatts_authorize_params_t_enc(void const * const p_void_struct,
  343. uint8_t * const p_buf,
  344. uint32_t buf_len,
  345. uint32_t * const p_index)
  346. {
  347. SER_STRUCT_ENC_BEGIN(ble_gatts_authorize_params_t);
  348. uint8_t ser_data = p_struct->update & 0x01;
  349. SER_PUSH_uint16(&p_struct->gatt_status);
  350. SER_PUSH_uint8(&ser_data);
  351. SER_PUSH_uint16(&p_struct->offset);
  352. SER_PUSH_len16data(p_struct->p_data, p_struct->len);
  353. SER_STRUCT_ENC_END;
  354. }
  355. uint32_t ble_gatts_authorize_params_t_dec(uint8_t const * const p_buf,
  356. uint32_t buf_len,
  357. uint32_t * const p_index,
  358. void * const p_void_struct)
  359. {
  360. SER_STRUCT_DEC_BEGIN(ble_gatts_authorize_params_t);
  361. uint8_t ser_data;
  362. SER_PULL_uint16(&p_struct->gatt_status);
  363. SER_PULL_uint8(&ser_data);
  364. SER_PULL_uint16(&p_struct->offset);
  365. SER_PULL_len16data((uint8_t **) &p_struct->p_data, &p_struct->len);
  366. p_struct->update = ser_data & 0x01;
  367. SER_STRUCT_DEC_END;
  368. }
  369. uint32_t ble_gatts_rw_authorize_reply_params_t_enc(void const * const p_void_struct,
  370. uint8_t * const p_buf,
  371. uint32_t buf_len,
  372. uint32_t * const p_index)
  373. {
  374. SER_STRUCT_ENC_BEGIN(ble_gatts_rw_authorize_reply_params_t);
  375. SER_PUSH_uint8(&p_struct->type);
  376. if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_READ)
  377. {
  378. SER_PUSH_FIELD(&p_struct->params.read, ble_gatts_authorize_params_t_enc);
  379. }
  380. else if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
  381. {
  382. SER_PUSH_FIELD(&p_struct->params.write, ble_gatts_authorize_params_t_enc);
  383. }
  384. else
  385. {
  386. return NRF_ERROR_INVALID_PARAM;
  387. }
  388. SER_STRUCT_ENC_END;
  389. }
  390. uint32_t ble_gatts_rw_authorize_reply_params_t_dec(uint8_t const * const p_buf,
  391. uint32_t buf_len,
  392. uint32_t * const p_index,
  393. void * const p_void_struct)
  394. {
  395. SER_STRUCT_DEC_BEGIN(ble_gatts_rw_authorize_reply_params_t);
  396. SER_PULL_uint8(&p_struct->type);
  397. if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_READ)
  398. {
  399. SER_PULL_FIELD(&p_struct->params.read, ble_gatts_authorize_params_t_dec);
  400. }
  401. else if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
  402. {
  403. SER_PULL_FIELD(&p_struct->params.write, ble_gatts_authorize_params_t_dec);
  404. }
  405. else
  406. {
  407. return NRF_ERROR_INVALID_PARAM;
  408. }
  409. SER_STRUCT_DEC_END;
  410. }
  411. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  412. uint32_t ble_gatts_enable_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_gatts_enable_params_t);
  418. uint8_t ser_data = p_struct->service_changed & 0x01;
  419. SER_PUSH_uint8(&ser_data);
  420. SER_PUSH_uint32(&p_struct->attr_tab_size);
  421. SER_STRUCT_ENC_END;
  422. }
  423. uint32_t ble_gatts_enable_params_t_dec(uint8_t const * const p_buf,
  424. uint32_t buf_len,
  425. uint32_t * const p_index,
  426. void * const p_void_struct)
  427. {
  428. SER_STRUCT_DEC_BEGIN(ble_gatts_enable_params_t);
  429. uint8_t ser_data;
  430. SER_PULL_uint8(&ser_data);
  431. SER_PULL_uint32(&p_struct->attr_tab_size);
  432. p_struct->service_changed = ser_data & 0x01;
  433. SER_STRUCT_DEC_END;
  434. }
  435. #endif
  436. uint32_t ble_gatts_value_t_enc(void const * const p_void_struct,
  437. uint8_t * const p_buf,
  438. uint32_t buf_len,
  439. uint32_t * const p_index)
  440. {
  441. SER_STRUCT_ENC_BEGIN(ble_gatts_value_t);
  442. SER_PUSH_uint16(&p_struct->offset);
  443. SER_PUSH_len16data(p_struct->p_value, p_struct->len);
  444. SER_STRUCT_ENC_END;
  445. }
  446. uint32_t ble_gatts_value_t_dec(uint8_t const * const p_buf,
  447. uint32_t buf_len,
  448. uint32_t * const p_index,
  449. void * const p_void_struct)
  450. {
  451. SER_STRUCT_DEC_BEGIN(ble_gatts_value_t);
  452. SER_PULL_uint16(&p_struct->offset);
  453. SER_PULL_len16data(&p_struct->p_value, &p_struct->len);
  454. SER_STRUCT_DEC_END;
  455. }
  456. uint32_t ble_gatts_evt_exchange_mtu_request_t_enc(void const * const p_void_struct,
  457. uint8_t * const p_buf,
  458. uint32_t buf_len,
  459. uint32_t * const p_index)
  460. {
  461. SER_STRUCT_ENC_BEGIN(ble_gatts_evt_exchange_mtu_request_t);
  462. SER_PUSH_uint16(&p_struct->client_rx_mtu);
  463. SER_STRUCT_ENC_END;
  464. }
  465. uint32_t ble_gatts_evt_exchange_mtu_request_t_dec(uint8_t const * const p_buf,
  466. uint32_t buf_len,
  467. uint32_t * const p_index,
  468. void * const p_void_struct)
  469. {
  470. SER_STRUCT_DEC_BEGIN(ble_gatts_evt_exchange_mtu_request_t);
  471. SER_PULL_uint16(&p_struct->client_rx_mtu);
  472. SER_STRUCT_DEC_END;
  473. }
  474. uint32_t ble_gatts_evt_hvc_t_enc(void const * const p_void_struct,
  475. uint8_t * const p_buf,
  476. uint32_t buf_len,
  477. uint32_t * const p_index)
  478. {
  479. SER_STRUCT_ENC_BEGIN(ble_gatts_evt_hvc_t);
  480. SER_PUSH_uint16(&p_struct->handle);
  481. SER_STRUCT_ENC_END;
  482. }
  483. uint32_t ble_gatts_evt_hvc_t_dec(uint8_t const * const p_buf,
  484. uint32_t buf_len,
  485. uint32_t * const p_index,
  486. void * const p_void_struct)
  487. {
  488. SER_STRUCT_DEC_BEGIN(ble_gatts_evt_hvc_t);
  489. SER_PULL_uint16(&p_struct->handle);
  490. SER_STRUCT_DEC_END;
  491. }
  492. uint32_t ble_gatts_evt_sys_attr_missing_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_gatts_evt_sys_attr_missing_t);
  498. SER_PUSH_uint8(&p_struct->hint);
  499. SER_STRUCT_ENC_END;
  500. }
  501. uint32_t ble_gatts_evt_sys_attr_missing_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_gatts_evt_sys_attr_missing_t);
  507. SER_PULL_uint8(&p_struct->hint);
  508. SER_STRUCT_DEC_END;
  509. }
  510. uint32_t ble_gatts_evt_timeout_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_gatts_evt_timeout_t);
  516. SER_PUSH_uint8(&p_struct->src);
  517. SER_STRUCT_ENC_END;
  518. }
  519. uint32_t ble_gatts_evt_timeout_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_gatts_evt_timeout_t);
  525. SER_PULL_uint8(&p_struct->src);
  526. SER_STRUCT_DEC_END;
  527. }
  528. #if NRF_SD_BLE_API_VERSION >= 4
  529. uint32_t ble_gatts_conn_cfg_t_enc(void const * const p_void_struct,
  530. uint8_t * const p_buf,
  531. uint32_t buf_len,
  532. uint32_t * const p_index)
  533. {
  534. SER_STRUCT_ENC_BEGIN(ble_gatts_conn_cfg_t);
  535. SER_PUSH_uint8(&p_struct->hvn_tx_queue_size);
  536. SER_STRUCT_ENC_END;
  537. }
  538. uint32_t ble_gatts_conn_cfg_t_dec(uint8_t const * const p_buf,
  539. uint32_t buf_len,
  540. uint32_t * const p_index,
  541. void * const p_void_struct)
  542. {
  543. SER_STRUCT_DEC_BEGIN(ble_gatts_conn_cfg_t);
  544. SER_PULL_uint8(&p_struct->hvn_tx_queue_size);
  545. SER_STRUCT_DEC_END;
  546. }
  547. uint32_t ble_gatts_cfg_service_changed_t_enc(void const * const p_void_struct,
  548. uint8_t * const p_buf,
  549. uint32_t buf_len,
  550. uint32_t * const p_index)
  551. {
  552. SER_STRUCT_ENC_BEGIN(ble_gatts_cfg_service_changed_t);
  553. uint8_t service_changed = p_struct->service_changed;
  554. SER_PUSH_uint8(&service_changed);
  555. SER_STRUCT_ENC_END;
  556. }
  557. uint32_t ble_gatts_cfg_service_changed_t_dec(uint8_t const * const p_buf,
  558. uint32_t buf_len,
  559. uint32_t * const p_index,
  560. void * const p_void_struct)
  561. {
  562. SER_STRUCT_DEC_BEGIN(ble_gatts_cfg_service_changed_t);
  563. uint8_t service_changed;
  564. SER_PULL_uint8(&service_changed);
  565. p_struct->service_changed = service_changed;
  566. SER_STRUCT_DEC_END;
  567. }
  568. uint32_t ble_gatts_cfg_attr_tab_size_t_enc(void const * const p_void_struct,
  569. uint8_t * const p_buf,
  570. uint32_t buf_len,
  571. uint32_t * const p_index)
  572. {
  573. SER_STRUCT_ENC_BEGIN(ble_gatts_cfg_attr_tab_size_t);
  574. SER_PUSH_uint32(&p_struct->attr_tab_size);
  575. SER_STRUCT_ENC_END;
  576. }
  577. uint32_t ble_gatts_cfg_attr_tab_size_t_dec(uint8_t const * const p_buf,
  578. uint32_t buf_len,
  579. uint32_t * const p_index,
  580. void * const p_void_struct)
  581. {
  582. SER_STRUCT_DEC_BEGIN(ble_gatts_cfg_attr_tab_size_t);
  583. SER_PULL_uint32(&p_struct->attr_tab_size);
  584. SER_STRUCT_DEC_END;
  585. }
  586. #endif