ble_l2cap_app.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. /**@file
  41. *
  42. * @defgroup ble_l2cap_app L2CAP Application command request encoders and command response decoders
  43. * @{
  44. * @ingroup ser_app_s130_codecs
  45. *
  46. * @brief L2CAP Application command request encoders and command response decoders.
  47. */
  48. #ifndef BLE_L2CAP_APP_H__
  49. #define BLE_L2CAP_APP_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 Register a CID with L2CAP.
  60. *
  61. * @details This registers a higher protocol layer with the L2CAP multiplexer, and is required prior to all operations on the CID.
  62. *
  63. * @param[in] cid L2CAP CID.
  64. * @param[in] p_buf Pointer to beginning of command response packet.
  65. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  66. * \c out: Length of encoded command packet.
  67. *
  68. * @retval NRF_SUCCESS Encoding success.
  69. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  70. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  71. */
  72. uint32_t ble_l2cap_cid_register_req_enc(uint16_t cid,
  73. uint8_t * const p_buf,
  74. uint32_t * const p_buf_len);
  75. /**
  76. * @brief Decodes response to @ref sd_ble_l2cap_cid_register command.
  77. *
  78. * @sa @ref ble_l2cap_cid_register_req_enc for command request encoder.
  79. *
  80. * @param[in] p_buf Pointer to beginning of command response packet.
  81. * @param[in] packet_len Length (in bytes) of response packet.
  82. * @param[out] p_result_code Command result code.
  83. *
  84. * @retval NRF_SUCCESS Decoding success.
  85. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  86. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  87. * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match
  88. * expected operation code.
  89. */
  90. uint32_t ble_l2cap_cid_register_rsp_dec(uint8_t const * const p_buf,
  91. uint32_t packet_len,
  92. uint32_t * const p_result_code);
  93. /**@brief Unregister a CID with L2CAP.
  94. *
  95. * @details This unregisters a previously registered higher protocol layer with the L2CAP multiplexer.
  96. *
  97. * @param[in] cid L2CAP CID.
  98. * @param[in] p_buf Pointer to beginning of command response packet.
  99. * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
  100. * \c out: Length of encoded command packet.
  101. *
  102. * @retval NRF_SUCCESS Encoding success.
  103. * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
  104. * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
  105. */
  106. uint32_t ble_l2cap_cid_unregister_req_enc(uint16_t cid,
  107. uint8_t * const p_buf,
  108. uint32_t * const p_buf_len);
  109. /**
  110. * @brief Decodes response to @ref sd_ble_l2cap_cid_unregister command.
  111. *
  112. * @sa @ref ble_l2cap_cid_unregister_req_enc for command request encoder.
  113. *
  114. * @param[in] p_buf Pointer to beginning of command response packet.
  115. * @param[in] packet_len Length (in bytes) of response packet.
  116. * @param[out] p_result_code Command result code.
  117. *
  118. * @retval NRF_SUCCESS Decoding success.
  119. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  120. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  121. * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match
  122. * expected operation code.
  123. */
  124. uint32_t ble_l2cap_cid_unregister_rsp_dec(uint8_t const * const p_buf,
  125. uint32_t packet_len,
  126. uint32_t * const p_result_code);
  127. /**@brief Transmit an L2CAP packet.
  128. *
  129. * @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore
  130. * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
  131. * See the documentation of @ref sd_ble_tx_packet_count_get for more details.
  132. *
  133. * @param[in] conn_handle Connection handle.
  134. * @param[in] p_l2cap_header Pointer to a packet header containing length and CID.
  135. * @param[in] p_data Pointer to the data to be transmitted.
  136. * @param[in] p_buf Pointer to beginning of command response packet.
  137. * @param[in,out] p_buf_len\ c in: Size of \p p_buf buffer.
  138. * \c out: Length of encoded command packet.
  139. *
  140. * @retval NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
  141. * @retval NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  142. * @retval NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
  143. * @retval NRF_ERROR_NOT_FOUND CID not found.
  144. * @retval NRF_ERROR_NO_MEM Not enough memory to complete operation.
  145. * @retval NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
  146. */
  147. uint32_t ble_l2cap_tx_req_enc(uint16_t conn_handle,
  148. ble_l2cap_header_t const * const p_l2cap_header,
  149. uint8_t const * const p_data,
  150. uint8_t * const p_buf,
  151. uint32_t * const p_buf_len);
  152. /**
  153. * @brief Decodes response to @ref sd_ble_l2cap_tx command.
  154. *
  155. * @sa @ref ble_l2cap_tx_req_enc for command request encoder.
  156. *
  157. * @param[in] p_buf Pointer to beginning of command response packet.
  158. * @param[in] packet_len Length (in bytes) of response packet.
  159. * @param[out] p_result_code Command result code.
  160. *
  161. * @retval NRF_SUCCESS Decoding success.
  162. * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
  163. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  164. * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match
  165. * expected operation code.
  166. */
  167. uint32_t ble_l2cap_tx_rsp_dec(uint8_t const * const p_buf,
  168. uint32_t packet_len,
  169. uint32_t * const p_result_code);
  170. #endif
  171. #if NRF_SD_BLE_API_VERSION >= 5
  172. uint32_t ble_l2cap_ch_setup_req_enc(uint16_t conn_handle,
  173. uint16_t * p_local_cid,
  174. ble_l2cap_ch_setup_params_t const *p_params,
  175. uint8_t * const p_buf,
  176. uint32_t * const p_buf_len);
  177. uint32_t ble_l2cap_ch_setup_rsp_dec(uint8_t const * const p_buf,
  178. uint32_t packet_len,
  179. uint16_t * p_local_cid,
  180. uint32_t * const p_result_code);
  181. uint32_t ble_l2cap_ch_release_req_enc(uint16_t conn_handle,
  182. uint16_t local_cid,
  183. uint8_t * const p_buf,
  184. uint32_t * const p_buf_len);
  185. uint32_t ble_l2cap_ch_release_rsp_dec(uint8_t const * const p_buf,
  186. uint32_t packet_len,
  187. uint32_t * const p_result_code);
  188. uint32_t ble_l2cap_ch_rx_req_enc(uint16_t conn_handle,
  189. uint16_t local_cid,
  190. ble_data_t const *p_sdu_buf,
  191. uint8_t * const p_buf,
  192. uint32_t * const p_buf_len);
  193. uint32_t ble_l2cap_ch_rx_rsp_dec(uint8_t const * const p_buf,
  194. uint32_t packet_len,
  195. uint32_t * const p_result_code);
  196. uint32_t ble_l2cap_ch_tx_req_enc(uint16_t conn_handle,
  197. uint16_t local_cid,
  198. ble_data_t const *p_sdu_buf,
  199. uint8_t * const p_buf,
  200. uint32_t * const p_buf_len);
  201. uint32_t ble_l2cap_ch_tx_rsp_dec(uint8_t const * const p_buf,
  202. uint32_t packet_len,
  203. uint32_t * const p_result_code);
  204. uint32_t ble_l2cap_ch_flow_control_req_enc(uint16_t conn_handle,
  205. uint16_t local_cid,
  206. uint16_t credits,
  207. uint16_t *p_credits,
  208. uint8_t * const p_buf,
  209. uint32_t * const p_buf_len);
  210. uint32_t ble_l2cap_ch_flow_control_rsp_dec(uint8_t const * const p_buf,
  211. uint32_t packet_len,
  212. uint16_t * p_credits,
  213. uint32_t * const p_result_code);
  214. #endif //NRF_SD_BLE_API_VERSION >= 5
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif //BLE_L2CAP_APP_H__
  219. /**
  220. @}
  221. */