ble_l2cap_conn.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /**
  2. * Copyright (c) 2011 - 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. /**@file
  41. *
  42. * @defgroup ble_l2cap_conn L2CAP Connectivity command request decoders and command response encoders
  43. * @{
  44. * @ingroup ser_conn_s130_codecs
  45. *
  46. * @brief L2CAP Connectivity command request decoders and command response encoders.
  47. */
  48. #ifndef BLE_L2CAP_CONN_H__
  49. #define BLE_L2CAP_CONN_H__
  50. #include "ble.h"
  51. #include "ble_types.h"
  52. #include "ble_ranges.h"
  53. #include "ble_err.h"
  54. #include "ble_l2cap.h"
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
  59. /**@brief Decodes @ref sd_ble_l2cap_cid_register command request.
  60. *
  61. * @sa @ref ble_l2cap_cid_register_rsp_enc for response encoding.
  62. *
  63. * @param[in] p_buf Pointer to beginning of command request packet.
  64. * @param[in] buf_len Length (in bytes) of response packet.
  65. * @param[in] p_cid Pointer to L2CAP CID.
  66. *
  67. * @retval NRF_SUCCESS Decoding success.
  68. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  69. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  70. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  71. */
  72. uint32_t ble_l2cap_cid_register_req_dec(uint8_t const * const p_buf,
  73. uint32_t buf_len,
  74. uint16_t * p_cid);
  75. /**@brief Encodes @ref sd_ble_l2cap_cid_register command response.
  76. *
  77. * @sa @ref ble_l2cap_cid_register_req_dec for request decoding.
  78. *
  79. * @param[in] return_code Return code indicating if command was successful or not.
  80. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  81. * returned.
  82. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  83. * \c out: Length of encoded command response packet.
  84. *
  85. * @retval NRF_SUCCESS Encoding success.
  86. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  87. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  88. */
  89. uint32_t ble_l2cap_cid_register_rsp_enc(uint32_t return_code,
  90. uint8_t * const p_buf,
  91. uint32_t * const p_buf_len);
  92. /**@brief Decodes @ref sd_ble_l2cap_cid_unregister command request.
  93. *
  94. * @sa @ref ble_l2cap_cid_unregister_rsp_enc for response encoding.
  95. *
  96. * @param[in] p_buf Pointer to beginning of command request packet.
  97. * @param[in] buf_len Length (in bytes) of response packet.
  98. * @param[in] p_cid Pointer to L2CAP CID.
  99. *
  100. * @retval NRF_SUCCESS Decoding success.
  101. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  102. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  103. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  104. */
  105. uint32_t ble_l2cap_cid_unregister_req_dec(uint8_t const * const p_buf,
  106. uint32_t buf_len,
  107. uint16_t * p_cid);
  108. /**@brief Encodes @ref sd_ble_l2cap_cid_unregister command response.
  109. *
  110. * @sa @ref ble_l2cap_cid_unregister_req_dec for request decoding.
  111. *
  112. * @param[in] return_code Return code indicating if command was successful or not.
  113. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  114. * returned.
  115. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  116. * \c out: Length of encoded command response packet.
  117. *
  118. * @retval NRF_SUCCESS Encoding success.
  119. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  120. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  121. */
  122. uint32_t ble_l2cap_cid_unregister_rsp_enc(uint32_t return_code,
  123. uint8_t * const p_buf,
  124. uint32_t * const p_buf_len);
  125. /**@brief Decodes @ref sd_ble_l2cap_tx command request.
  126. *
  127. * @sa @ref ble_l2cap_tx_rsp_enc for response encoding.
  128. *
  129. * @param[in] p_buf Pointer to beginning of command request packet.
  130. * @param[in] buf_len Length (in bytes) of response packet.
  131. * @param[in] p_conn_handle Pointer to connection handle.
  132. * @param[in] pp_l2cap_header Pointer to pointer to L2CAP header.
  133. * @param[in] pp_data Pointer to pointer L2CAP data.
  134. *
  135. * @retval NRF_SUCCESS Decoding success.
  136. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  137. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  138. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  139. */
  140. uint32_t ble_l2cap_tx_req_dec(uint8_t const * const p_buf,
  141. uint32_t const buf_len,
  142. uint16_t * p_conn_handle,
  143. ble_l2cap_header_t * * const pp_l2cap_header,
  144. uint8_t const * * pp_data);
  145. /**@brief Encodes @ref sd_ble_l2cap_tx command response.
  146. *
  147. * @sa @ref ble_l2cap_tx_req_dec for request decoding.
  148. *
  149. * @param[in] return_code Return code indicating if command was successful or not.
  150. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  151. * returned.
  152. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  153. * \c out: Length of encoded command response packet.
  154. *
  155. * @retval NRF_SUCCESS Encoding success.
  156. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  157. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  158. */
  159. uint32_t ble_l2cap_tx_rsp_enc(uint32_t return_code,
  160. uint8_t * const p_buf,
  161. uint32_t * const p_buf_len);
  162. #endif
  163. #if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5
  164. /**@brief Decodes @ref sd_ble_l2cap_ch_setup command request.
  165. *
  166. * @sa @ref ble_l2cap_ch_setup_rsp_enc for response encoding.
  167. *
  168. * @param[in] p_buf Pointer to beginning of command request packet.
  169. * @param[in] buf_len Length (in bytes) of response packet.
  170. * @param[in] p_conn_handle Pointer to connection handle.
  171. * @param[in, out] pp_local_cid Pointer to pointer to local cid.
  172. * @param[in, out] pp_params Pointer to pointer to params.
  173. *
  174. * @retval NRF_SUCCESS Decoding success.
  175. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  176. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  177. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  178. */
  179. uint32_t ble_l2cap_ch_setup_req_dec(uint8_t const * const p_buf,
  180. uint16_t packet_len,
  181. uint16_t * p_conn_handle,
  182. uint16_t * * pp_local_cid,
  183. ble_l2cap_ch_setup_params_t * * const pp_params);
  184. /**@brief Encodes @ref sd_ble_l2cap_ch_setup command response.
  185. *
  186. * @sa @ref ble_l2cap_ch_setup_req_dec for request decoding.
  187. *
  188. * @param[in] return_code Return code indicating if command was successful or not.
  189. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  190. * returned.
  191. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  192. * \c out: Length of encoded command response packet.
  193. * @param[p_local_cid Pointer to local cid.
  194. *
  195. * @retval NRF_SUCCESS Encoding success.
  196. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  197. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  198. */
  199. uint32_t ble_l2cap_ch_setup_rsp_enc(uint32_t return_code,
  200. uint8_t * const p_buf,
  201. uint32_t * const p_buf_len,
  202. uint16_t * p_local_cid);
  203. /**@brief Decodes @ref sd_ble_l2cap_ch_release command request.
  204. *
  205. * @sa @ref ble_l2cap_ch_release_rsp_enc for response encoding.
  206. *
  207. * @param[in] p_buf Pointer to beginning of command request packet.
  208. * @param[in] buf_len Length (in bytes) of response packet.
  209. * @param[in] p_conn_handle Pointer to connection handle.
  210. * @param[in] p_local_cid Pointer to local cid.
  211. * @param[in] pp_data Pointer to pointer L2CAP data.
  212. *
  213. * @retval NRF_SUCCESS Decoding success.
  214. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  215. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  216. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  217. */
  218. uint32_t ble_l2cap_ch_release_req_dec(uint8_t const * const p_buf,
  219. uint16_t packet_len,
  220. uint16_t * p_conn_handle,
  221. uint16_t * p_local_cid);
  222. /**@brief Encodes @ref sd_ble_l2cap_ch_releasecommand response.
  223. *
  224. * @sa @ref ble_l2cap_ch_release_req_dec for request decoding.
  225. *
  226. * @param[in] return_code Return code indicating if command was successful or not.
  227. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  228. * returned.
  229. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  230. * \c out: Length of encoded command response packet.
  231. *
  232. * @retval NRF_SUCCESS Encoding success.
  233. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  234. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  235. */
  236. uint32_t ble_l2cap_ch_release_rsp_enc(uint32_t return_code,
  237. uint8_t * const p_buf,
  238. uint32_t * const p_buf_len);
  239. /**@brief Decodes @ref sd_ble_l2cap_ch_rx command request.
  240. *
  241. * @sa @ref ble_l2cap_ch_rx_rsp_enc for response encoding.
  242. *
  243. * @param[in] p_buf Pointer to beginning of command request packet.
  244. * @param[in] buf_len Length (in bytes) of response packet.
  245. * @param[in] p_conn_handle Pointer to connection handle.
  246. * @param[in] p_local_cid Pointer to local cid.
  247. * @param[in] pp_sdu_buf Pointer to pointer to SDU buf.
  248. *
  249. * @retval NRF_SUCCESS Decoding success.
  250. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  251. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  252. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  253. */
  254. uint32_t ble_l2cap_ch_rx_req_dec(uint8_t const * const p_buf,
  255. uint16_t packet_len,
  256. uint16_t * p_conn_handle,
  257. uint16_t * p_local_cid,
  258. ble_data_t * * pp_sdu_buf);
  259. /**@brief Encodes @ref sd_ble_l2cap_ch_rx command response.
  260. *
  261. * @sa @ref ble_l2cap_ch_rx_req_dec for request decoding.
  262. *
  263. * @param[in] return_code Return code indicating if command was successful or not.
  264. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  265. * returned.
  266. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  267. * \c out: Length of encoded command response packet.
  268. *
  269. * @retval NRF_SUCCESS Encoding success.
  270. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  271. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  272. */
  273. uint32_t ble_l2cap_ch_rx_rsp_enc(uint32_t return_code,
  274. uint8_t * const p_buf,
  275. uint32_t * const p_buf_len);
  276. /**@brief Decodes @ref sd_ble_l2cap_ch_tx command request.
  277. *
  278. * @sa @ref ble_l2cap_ch_tx_rsp_enc for response encoding.
  279. *
  280. * @param[in] p_buf Pointer to beginning of command request packet.
  281. * @param[in] buf_len Length (in bytes) of response packet.
  282. * @param[in] p_conn_handle Pointer to connection handle.
  283. * @param[in] p_local_cid Pointer to local cid.
  284. * @param[in] pp_sdu_buf Pointer to pointer to SDU buf.
  285. *
  286. * @retval NRF_SUCCESS Decoding success.
  287. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  288. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  289. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  290. */
  291. uint32_t ble_l2cap_ch_tx_req_dec(uint8_t const * const p_buf,
  292. uint16_t packet_len,
  293. uint16_t * p_conn_handle,
  294. uint16_t * p_local_cid,
  295. ble_data_t * * const pp_sdu_buf);
  296. /**@brief Encodes @ref sd_ble_l2cap_ch_tx command response.
  297. *
  298. * @sa @ref ble_l2cap_ch_tx_req_dec for request decoding.
  299. *
  300. * @param[in] return_code Return code indicating if command was successful or not.
  301. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  302. * returned.
  303. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  304. * \c out: Length of encoded command response packet.
  305. *
  306. * @retval NRF_SUCCESS Encoding success.
  307. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  308. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  309. */
  310. uint32_t ble_l2cap_ch_tx_rsp_enc(uint32_t return_code,
  311. uint8_t * const p_buf,
  312. uint32_t * const p_buf_len);
  313. /**@brief Decodes @ref sd_ble_l2cap_ch_flow_control command request.
  314. *
  315. * @sa @ref ble_l2cap_ch_flow_control_rsp_enc for response encoding.
  316. *
  317. * @param[in] p_buf Pointer to beginning of command request packet.
  318. * @param[in] buf_len Length (in bytes) of response packet.
  319. * @param[in] p_conn_handle Pointer to connection handle.
  320. * @param[in] p_local_cid Pointer to local cid.
  321. * @param[in] p_credits Pointer to credits.
  322. * @param[in,out] pp_credits Pointer to pointer to credits.
  323. *
  324. * @retval NRF_SUCCESS Decoding success.
  325. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  326. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  327. * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
  328. */
  329. uint32_t ble_l2cap_ch_flow_control_req_dec(uint8_t const * const p_buf,
  330. uint16_t packet_len,
  331. uint16_t * p_conn_handle,
  332. uint16_t * p_local_cid,
  333. uint16_t * p_credits,
  334. uint16_t * * pp_credits);
  335. /**@brief Encodes @ref sd_ble_l2cap_ch_flow_control command response.
  336. *
  337. * @sa @ref ble_l2cap_ch_flow_control_req_dec for request decoding.
  338. *
  339. * @param[in] return_code Return code indicating if command was successful or not.
  340. * @param[out] p_buf Pointer to buffer where encoded data command response will be
  341. * returned.
  342. * @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
  343. * \c out: Length of encoded command response packet.
  344. * @param[in] p_credits Pointer to credits.
  345. *
  346. * @retval NRF_SUCCESS Encoding success.
  347. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  348. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  349. */
  350. uint32_t ble_l2cap_ch_flow_control_rsp_enc(uint32_t return_code,
  351. uint8_t * const p_buf,
  352. uint32_t * const p_buf_len,
  353. uint16_t const * const p_credits);
  354. #endif
  355. #ifdef __cplusplus
  356. }
  357. #endif
  358. #endif //BLE_L2CAP_CONN_H__
  359. /**
  360. @}
  361. */