ble_l2cap.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * Copyright (c) 2011 - 2020, Nordic Semiconductor ASA
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form, except as embedded into a Nordic
  12. * Semiconductor ASA integrated circuit in a product or a software update for
  13. * such product, must reproduce the above copyright notice, this list of
  14. * conditions and the following disclaimer in the documentation and/or other
  15. * materials provided with the distribution.
  16. *
  17. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * 4. This software, with or without modification, must only be used with a
  22. * Nordic Semiconductor ASA integrated circuit.
  23. *
  24. * 5. Any software provided in binary form under this license must not be reverse
  25. * engineered, decompiled, modified and/or disassembled.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  28. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  33. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  36. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. /**
  39. @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
  40. @{
  41. @brief Definitions and prototypes for the L2CAP interface.
  42. */
  43. #ifndef BLE_L2CAP_H__
  44. #define BLE_L2CAP_H__
  45. #include <stdint.h>
  46. #include "nrf_svc.h"
  47. #include "nrf_error.h"
  48. #include "ble_ranges.h"
  49. #include "ble_types.h"
  50. #include "ble_err.h"
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /**@addtogroup BLE_L2CAP_TERMINOLOGY Terminology
  55. * @{
  56. * @details
  57. *
  58. * L2CAP SDU
  59. * - A data unit that the application can send/receive to/from a peer.
  60. *
  61. * L2CAP PDU
  62. * - A data unit that is exchanged between local and remote L2CAP entities.
  63. * It consists of L2CAP protocol control information and payload fields.
  64. * The payload field can contain an L2CAP SDU or a part of an L2CAP SDU.
  65. *
  66. * L2CAP MTU
  67. * - The maximum length of an L2CAP SDU.
  68. *
  69. * L2CAP MPS
  70. * - The maximum length of an L2CAP PDU payload field.
  71. *
  72. * Credits
  73. * - A value indicating the number of L2CAP PDUs that the receiver of the credit can send to the peer.
  74. * @} */
  75. /**@addtogroup BLE_L2CAP_ENUMERATIONS Enumerations
  76. * @{ */
  77. /**@brief L2CAP API SVC numbers. */
  78. enum BLE_L2CAP_SVCS
  79. {
  80. SD_BLE_L2CAP_CH_SETUP = BLE_L2CAP_SVC_BASE + 0, /**< Set up an L2CAP channel. */
  81. SD_BLE_L2CAP_CH_RELEASE = BLE_L2CAP_SVC_BASE + 1, /**< Release an L2CAP channel. */
  82. SD_BLE_L2CAP_CH_RX = BLE_L2CAP_SVC_BASE + 2, /**< Receive an SDU on an L2CAP channel. */
  83. SD_BLE_L2CAP_CH_TX = BLE_L2CAP_SVC_BASE + 3, /**< Transmit an SDU on an L2CAP channel. */
  84. SD_BLE_L2CAP_CH_FLOW_CONTROL = BLE_L2CAP_SVC_BASE + 4, /**< Advanced SDU reception flow control. */
  85. };
  86. /**@brief L2CAP Event IDs. */
  87. enum BLE_L2CAP_EVTS
  88. {
  89. BLE_L2CAP_EVT_CH_SETUP_REQUEST = BLE_L2CAP_EVT_BASE + 0, /**< L2CAP Channel Setup Request event.
  90. \n Reply with @ref sd_ble_l2cap_ch_setup.
  91. \n See @ref ble_l2cap_evt_ch_setup_request_t. */
  92. BLE_L2CAP_EVT_CH_SETUP_REFUSED = BLE_L2CAP_EVT_BASE + 1, /**< L2CAP Channel Setup Refused event.
  93. \n See @ref ble_l2cap_evt_ch_setup_refused_t. */
  94. BLE_L2CAP_EVT_CH_SETUP = BLE_L2CAP_EVT_BASE + 2, /**< L2CAP Channel Setup Completed event.
  95. \n See @ref ble_l2cap_evt_ch_setup_t. */
  96. BLE_L2CAP_EVT_CH_RELEASED = BLE_L2CAP_EVT_BASE + 3, /**< L2CAP Channel Released event.
  97. \n No additional event structure applies. */
  98. BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED = BLE_L2CAP_EVT_BASE + 4, /**< L2CAP Channel SDU data buffer released event.
  99. \n See @ref ble_l2cap_evt_ch_sdu_buf_released_t. */
  100. BLE_L2CAP_EVT_CH_CREDIT = BLE_L2CAP_EVT_BASE + 5, /**< L2CAP Channel Credit received.
  101. \n See @ref ble_l2cap_evt_ch_credit_t. */
  102. BLE_L2CAP_EVT_CH_RX = BLE_L2CAP_EVT_BASE + 6, /**< L2CAP Channel SDU received.
  103. \n See @ref ble_l2cap_evt_ch_rx_t. */
  104. BLE_L2CAP_EVT_CH_TX = BLE_L2CAP_EVT_BASE + 7, /**< L2CAP Channel SDU transmitted.
  105. \n See @ref ble_l2cap_evt_ch_tx_t. */
  106. };
  107. /** @} */
  108. /**@addtogroup BLE_L2CAP_DEFINES Defines
  109. * @{ */
  110. /**@brief Maximum number of L2CAP channels per connection. */
  111. #define BLE_L2CAP_CH_COUNT_MAX (64)
  112. /**@brief Minimum L2CAP MTU, in bytes. */
  113. #define BLE_L2CAP_MTU_MIN (23)
  114. /**@brief Minimum L2CAP MPS, in bytes. */
  115. #define BLE_L2CAP_MPS_MIN (23)
  116. /**@brief Invalid CID. */
  117. #define BLE_L2CAP_CID_INVALID (0x0000)
  118. /**@brief Default number of credits for @ref sd_ble_l2cap_ch_flow_control. */
  119. #define BLE_L2CAP_CREDITS_DEFAULT (1)
  120. /**@defgroup BLE_L2CAP_CH_SETUP_REFUSED_SRCS L2CAP channel setup refused sources
  121. * @{ */
  122. #define BLE_L2CAP_CH_SETUP_REFUSED_SRC_LOCAL (0x01) /**< Local. */
  123. #define BLE_L2CAP_CH_SETUP_REFUSED_SRC_REMOTE (0x02) /**< Remote. */
  124. /** @} */
  125. /** @defgroup BLE_L2CAP_CH_STATUS_CODES L2CAP channel status codes
  126. * @{ */
  127. #define BLE_L2CAP_CH_STATUS_CODE_SUCCESS (0x0000) /**< Success. */
  128. #define BLE_L2CAP_CH_STATUS_CODE_LE_PSM_NOT_SUPPORTED (0x0002) /**< LE_PSM not supported. */
  129. #define BLE_L2CAP_CH_STATUS_CODE_NO_RESOURCES (0x0004) /**< No resources available. */
  130. #define BLE_L2CAP_CH_STATUS_CODE_INSUFF_AUTHENTICATION (0x0005) /**< Insufficient authentication. */
  131. #define BLE_L2CAP_CH_STATUS_CODE_INSUFF_AUTHORIZATION (0x0006) /**< Insufficient authorization. */
  132. #define BLE_L2CAP_CH_STATUS_CODE_INSUFF_ENC_KEY_SIZE (0x0007) /**< Insufficient encryption key size. */
  133. #define BLE_L2CAP_CH_STATUS_CODE_INSUFF_ENC (0x0008) /**< Insufficient encryption. */
  134. #define BLE_L2CAP_CH_STATUS_CODE_INVALID_SCID (0x0009) /**< Invalid Source CID. */
  135. #define BLE_L2CAP_CH_STATUS_CODE_SCID_ALLOCATED (0x000A) /**< Source CID already allocated. */
  136. #define BLE_L2CAP_CH_STATUS_CODE_UNACCEPTABLE_PARAMS (0x000B) /**< Unacceptable parameters. */
  137. #define BLE_L2CAP_CH_STATUS_CODE_NOT_UNDERSTOOD (0x8000) /**< Command Reject received instead of LE Credit Based Connection Response. */
  138. #define BLE_L2CAP_CH_STATUS_CODE_TIMEOUT (0xC000) /**< Operation timed out. */
  139. /** @} */
  140. /** @} */
  141. /**@addtogroup BLE_L2CAP_STRUCTURES Structures
  142. * @{ */
  143. /**
  144. * @brief BLE L2CAP connection configuration parameters, set with @ref sd_ble_cfg_set.
  145. *
  146. * @note These parameters are set per connection, so all L2CAP channels created on this connection
  147. * will have the same parameters.
  148. *
  149. * @retval ::NRF_ERROR_INVALID_PARAM One or more of the following is true:
  150. * - rx_mps is smaller than @ref BLE_L2CAP_MPS_MIN.
  151. * - tx_mps is smaller than @ref BLE_L2CAP_MPS_MIN.
  152. * - ch_count is greater than @ref BLE_L2CAP_CH_COUNT_MAX.
  153. * @retval ::NRF_ERROR_NO_MEM rx_mps or tx_mps is set too high.
  154. */
  155. typedef struct
  156. {
  157. uint16_t rx_mps; /**< The maximum L2CAP PDU payload size, in bytes, that L2CAP shall
  158. be able to receive on L2CAP channels on connections with this
  159. configuration. The minimum value is @ref BLE_L2CAP_MPS_MIN. */
  160. uint16_t tx_mps; /**< The maximum L2CAP PDU payload size, in bytes, that L2CAP shall
  161. be able to transmit on L2CAP channels on connections with this
  162. configuration. The minimum value is @ref BLE_L2CAP_MPS_MIN. */
  163. uint8_t rx_queue_size; /**< Number of SDU data buffers that can be queued for reception per
  164. L2CAP channel. The minimum value is one. */
  165. uint8_t tx_queue_size; /**< Number of SDU data buffers that can be queued for transmission
  166. per L2CAP channel. The minimum value is one. */
  167. uint8_t ch_count; /**< Number of L2CAP channels the application can create per connection
  168. with this configuration. The default value is zero, the maximum
  169. value is @ref BLE_L2CAP_CH_COUNT_MAX.
  170. @note if this parameter is set to zero, all other parameters in
  171. @ref ble_l2cap_conn_cfg_t are ignored. */
  172. } ble_l2cap_conn_cfg_t;
  173. /**@brief L2CAP channel RX parameters. */
  174. typedef struct
  175. {
  176. uint16_t rx_mtu; /**< The maximum L2CAP SDU size, in bytes, that L2CAP shall be able to
  177. receive on this L2CAP channel.
  178. - Must be equal to or greater than @ref BLE_L2CAP_MTU_MIN. */
  179. uint16_t rx_mps; /**< The maximum L2CAP PDU payload size, in bytes, that L2CAP shall be
  180. able to receive on this L2CAP channel.
  181. - Must be equal to or greater than @ref BLE_L2CAP_MPS_MIN.
  182. - Must be equal to or less than @ref ble_l2cap_conn_cfg_t::rx_mps. */
  183. ble_data_t sdu_buf; /**< SDU data buffer for reception.
  184. - If @ref ble_data_t::p_data is non-NULL, initial credits are
  185. issued to the peer.
  186. - If @ref ble_data_t::p_data is NULL, no initial credits are
  187. issued to the peer. */
  188. } ble_l2cap_ch_rx_params_t;
  189. /**@brief L2CAP channel setup parameters. */
  190. typedef struct
  191. {
  192. ble_l2cap_ch_rx_params_t rx_params; /**< L2CAP channel RX parameters. */
  193. uint16_t le_psm; /**< LE Protocol/Service Multiplexer. Used when requesting
  194. setup of an L2CAP channel, ignored otherwise. */
  195. uint16_t status; /**< Status code, see @ref BLE_L2CAP_CH_STATUS_CODES.
  196. Used when replying to a setup request of an L2CAP
  197. channel, ignored otherwise. */
  198. } ble_l2cap_ch_setup_params_t;
  199. /**@brief L2CAP channel TX parameters. */
  200. typedef struct
  201. {
  202. uint16_t tx_mtu; /**< The maximum L2CAP SDU size, in bytes, that L2CAP is able to
  203. transmit on this L2CAP channel. */
  204. uint16_t peer_mps; /**< The maximum L2CAP PDU payload size, in bytes, that the peer is
  205. able to receive on this L2CAP channel. */
  206. uint16_t tx_mps; /**< The maximum L2CAP PDU payload size, in bytes, that L2CAP is able
  207. to transmit on this L2CAP channel. This is effective tx_mps,
  208. selected by the SoftDevice as
  209. MIN( @ref ble_l2cap_ch_tx_params_t::peer_mps, @ref ble_l2cap_conn_cfg_t::tx_mps ) */
  210. uint16_t credits; /**< Initial credits given by the peer. */
  211. } ble_l2cap_ch_tx_params_t;
  212. /**@brief L2CAP Channel Setup Request event. */
  213. typedef struct
  214. {
  215. ble_l2cap_ch_tx_params_t tx_params; /**< L2CAP channel TX parameters. */
  216. uint16_t le_psm; /**< LE Protocol/Service Multiplexer. */
  217. } ble_l2cap_evt_ch_setup_request_t;
  218. /**@brief L2CAP Channel Setup Refused event. */
  219. typedef struct
  220. {
  221. uint8_t source; /**< Source, see @ref BLE_L2CAP_CH_SETUP_REFUSED_SRCS */
  222. uint16_t status; /**< Status code, see @ref BLE_L2CAP_CH_STATUS_CODES */
  223. } ble_l2cap_evt_ch_setup_refused_t;
  224. /**@brief L2CAP Channel Setup Completed event. */
  225. typedef struct
  226. {
  227. ble_l2cap_ch_tx_params_t tx_params; /**< L2CAP channel TX parameters. */
  228. } ble_l2cap_evt_ch_setup_t;
  229. /**@brief L2CAP Channel SDU Data Buffer Released event. */
  230. typedef struct
  231. {
  232. ble_data_t sdu_buf; /**< Returned reception or transmission SDU data buffer. The SoftDevice
  233. returns SDU data buffers supplied by the application, which have
  234. not yet been returned previously via a @ref BLE_L2CAP_EVT_CH_RX or
  235. @ref BLE_L2CAP_EVT_CH_TX event. */
  236. } ble_l2cap_evt_ch_sdu_buf_released_t;
  237. /**@brief L2CAP Channel Credit received event. */
  238. typedef struct
  239. {
  240. uint16_t credits; /**< Additional credits given by the peer. */
  241. } ble_l2cap_evt_ch_credit_t;
  242. /**@brief L2CAP Channel received SDU event. */
  243. typedef struct
  244. {
  245. uint16_t sdu_len; /**< Total SDU length, in bytes. */
  246. ble_data_t sdu_buf; /**< SDU data buffer.
  247. @note If there is not enough space in the buffer
  248. (sdu_buf.len < sdu_len) then the rest of the SDU will be
  249. silently discarded by the SoftDevice. */
  250. } ble_l2cap_evt_ch_rx_t;
  251. /**@brief L2CAP Channel transmitted SDU event. */
  252. typedef struct
  253. {
  254. ble_data_t sdu_buf; /**< SDU data buffer. */
  255. } ble_l2cap_evt_ch_tx_t;
  256. /**@brief L2CAP event structure. */
  257. typedef struct
  258. {
  259. uint16_t conn_handle; /**< Connection Handle on which the event occured. */
  260. uint16_t local_cid; /**< Local Channel ID of the L2CAP channel, or
  261. @ref BLE_L2CAP_CID_INVALID if not present. */
  262. union
  263. {
  264. ble_l2cap_evt_ch_setup_request_t ch_setup_request; /**< L2CAP Channel Setup Request Event Parameters. */
  265. ble_l2cap_evt_ch_setup_refused_t ch_setup_refused; /**< L2CAP Channel Setup Refused Event Parameters. */
  266. ble_l2cap_evt_ch_setup_t ch_setup; /**< L2CAP Channel Setup Completed Event Parameters. */
  267. ble_l2cap_evt_ch_sdu_buf_released_t ch_sdu_buf_released;/**< L2CAP Channel SDU Data Buffer Released Event Parameters. */
  268. ble_l2cap_evt_ch_credit_t credit; /**< L2CAP Channel Credit Received Event Parameters. */
  269. ble_l2cap_evt_ch_rx_t rx; /**< L2CAP Channel SDU Received Event Parameters. */
  270. ble_l2cap_evt_ch_tx_t tx; /**< L2CAP Channel SDU Transmitted Event Parameters. */
  271. } params; /**< Event Parameters. */
  272. } ble_l2cap_evt_t;
  273. /** @} */
  274. /**@addtogroup BLE_L2CAP_FUNCTIONS Functions
  275. * @{ */
  276. /**@brief Set up an L2CAP channel.
  277. *
  278. * @details This function is used to:
  279. * - Request setup of an L2CAP channel: sends an LE Credit Based Connection Request packet to a peer.
  280. * - Reply to a setup request of an L2CAP channel (if called in response to a
  281. * @ref BLE_L2CAP_EVT_CH_SETUP_REQUEST event): sends an LE Credit Based Connection
  282. * Response packet to a peer.
  283. *
  284. * @note A call to this function will require the application to keep the SDU data buffer alive
  285. * until the SDU data buffer is returned in @ref BLE_L2CAP_EVT_CH_RX or
  286. * @ref BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED event.
  287. *
  288. * @events
  289. * @event{@ref BLE_L2CAP_EVT_CH_SETUP, Setup successful.}
  290. * @event{@ref BLE_L2CAP_EVT_CH_SETUP_REFUSED, Setup failed.}
  291. * @endevents
  292. *
  293. * @mscs
  294. * @mmsc{@ref BLE_L2CAP_CH_SETUP_MSC}
  295. * @endmscs
  296. *
  297. * @param[in] conn_handle Connection Handle.
  298. * @param[in,out] p_local_cid Pointer to a uint16_t containing Local Channel ID of the L2CAP channel:
  299. * - As input: @ref BLE_L2CAP_CID_INVALID when requesting setup of an L2CAP
  300. * channel or local_cid provided in the @ref BLE_L2CAP_EVT_CH_SETUP_REQUEST
  301. * event when replying to a setup request of an L2CAP channel.
  302. * - As output: local_cid for this channel.
  303. * @param[in] p_params L2CAP channel parameters.
  304. *
  305. * @retval ::NRF_SUCCESS Successfully queued request or response for transmission.
  306. * @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
  307. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  308. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  309. * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
  310. * @retval ::NRF_ERROR_INVALID_LENGTH Supplied higher rx_mps than has been configured on this link.
  311. * @retval ::NRF_ERROR_INVALID_STATE Invalid State to perform operation (L2CAP channel already set up).
  312. * @retval ::NRF_ERROR_NOT_FOUND CID not found.
  313. * @retval ::NRF_ERROR_RESOURCES The limit has been reached for available L2CAP channels,
  314. * see @ref ble_l2cap_conn_cfg_t::ch_count.
  315. */
  316. SVCALL(SD_BLE_L2CAP_CH_SETUP, uint32_t, sd_ble_l2cap_ch_setup(uint16_t conn_handle, uint16_t *p_local_cid, ble_l2cap_ch_setup_params_t const *p_params));
  317. /**@brief Release an L2CAP channel.
  318. *
  319. * @details This sends a Disconnection Request packet to a peer.
  320. *
  321. * @events
  322. * @event{@ref BLE_L2CAP_EVT_CH_RELEASED, Release complete.}
  323. * @endevents
  324. *
  325. * @mscs
  326. * @mmsc{@ref BLE_L2CAP_CH_RELEASE_MSC}
  327. * @endmscs
  328. *
  329. * @param[in] conn_handle Connection Handle.
  330. * @param[in] local_cid Local Channel ID of the L2CAP channel.
  331. *
  332. * @retval ::NRF_SUCCESS Successfully queued request for transmission.
  333. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  334. * @retval ::NRF_ERROR_INVALID_STATE Invalid State to perform operation (Setup or release is
  335. * in progress for the L2CAP channel).
  336. * @retval ::NRF_ERROR_NOT_FOUND CID not found.
  337. */
  338. SVCALL(SD_BLE_L2CAP_CH_RELEASE, uint32_t, sd_ble_l2cap_ch_release(uint16_t conn_handle, uint16_t local_cid));
  339. /**@brief Receive an SDU on an L2CAP channel.
  340. *
  341. * @details This may issue additional credits to the peer using an LE Flow Control Credit packet.
  342. *
  343. * @note A call to this function will require the application to keep the memory pointed by
  344. * @ref ble_data_t::p_data alive until the SDU data buffer is returned in @ref BLE_L2CAP_EVT_CH_RX
  345. * or @ref BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED event.
  346. *
  347. * @note The SoftDevice can queue up to @ref ble_l2cap_conn_cfg_t::rx_queue_size SDU data buffers
  348. * for reception per L2CAP channel.
  349. *
  350. * @events
  351. * @event{@ref BLE_L2CAP_EVT_CH_RX, The SDU is received.}
  352. * @endevents
  353. *
  354. * @mscs
  355. * @mmsc{@ref BLE_L2CAP_CH_RX_MSC}
  356. * @endmscs
  357. *
  358. * @param[in] conn_handle Connection Handle.
  359. * @param[in] local_cid Local Channel ID of the L2CAP channel.
  360. * @param[in] p_sdu_buf Pointer to the SDU data buffer.
  361. *
  362. * @retval ::NRF_SUCCESS Buffer accepted.
  363. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  364. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  365. * @retval ::NRF_ERROR_INVALID_STATE Invalid State to perform operation (Setup or release is
  366. * in progress for an L2CAP channel).
  367. * @retval ::NRF_ERROR_NOT_FOUND CID not found.
  368. * @retval ::NRF_ERROR_RESOURCES Too many SDU data buffers supplied. Wait for a
  369. * @ref BLE_L2CAP_EVT_CH_RX event and retry.
  370. */
  371. SVCALL(SD_BLE_L2CAP_CH_RX, uint32_t, sd_ble_l2cap_ch_rx(uint16_t conn_handle, uint16_t local_cid, ble_data_t const *p_sdu_buf));
  372. /**@brief Transmit an SDU on an L2CAP channel.
  373. *
  374. * @note A call to this function will require the application to keep the memory pointed by
  375. * @ref ble_data_t::p_data alive until the SDU data buffer is returned in @ref BLE_L2CAP_EVT_CH_TX
  376. * or @ref BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED event.
  377. *
  378. * @note The SoftDevice can queue up to @ref ble_l2cap_conn_cfg_t::tx_queue_size SDUs for
  379. * transmission per L2CAP channel.
  380. *
  381. * @note The application can keep track of the available credits for transmission by following
  382. * the procedure below:
  383. * - Store initial credits given by the peer in a variable.
  384. * (Initial credits are provided in a @ref BLE_L2CAP_EVT_CH_SETUP event.)
  385. * - Decrement the variable, which stores the currently available credits, by
  386. * ceiling((@ref ble_data_t::len + 2) / tx_mps) when a call to this function returns
  387. * @ref NRF_SUCCESS. (tx_mps is provided in a @ref BLE_L2CAP_EVT_CH_SETUP event.)
  388. * - Increment the variable, which stores the currently available credits, by additional
  389. * credits given by the peer in a @ref BLE_L2CAP_EVT_CH_CREDIT event.
  390. *
  391. * @events
  392. * @event{@ref BLE_L2CAP_EVT_CH_TX, The SDU is transmitted.}
  393. * @endevents
  394. *
  395. * @mscs
  396. * @mmsc{@ref BLE_L2CAP_CH_TX_MSC}
  397. * @endmscs
  398. *
  399. * @param[in] conn_handle Connection Handle.
  400. * @param[in] local_cid Local Channel ID of the L2CAP channel.
  401. * @param[in] p_sdu_buf Pointer to the SDU data buffer.
  402. *
  403. * @retval ::NRF_SUCCESS Successfully queued L2CAP SDU for transmission.
  404. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  405. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  406. * @retval ::NRF_ERROR_INVALID_STATE Invalid State to perform operation (Setup or release is
  407. * in progress for the L2CAP channel).
  408. * @retval ::NRF_ERROR_NOT_FOUND CID not found.
  409. * @retval ::NRF_ERROR_DATA_SIZE Invalid SDU length supplied, must not be more than
  410. * @ref ble_l2cap_ch_tx_params_t::tx_mtu provided in
  411. * @ref BLE_L2CAP_EVT_CH_SETUP event.
  412. * @retval ::NRF_ERROR_RESOURCES Too many SDUs queued for transmission. Wait for a
  413. * @ref BLE_L2CAP_EVT_CH_TX event and retry.
  414. */
  415. SVCALL(SD_BLE_L2CAP_CH_TX, uint32_t, sd_ble_l2cap_ch_tx(uint16_t conn_handle, uint16_t local_cid, ble_data_t const *p_sdu_buf));
  416. /**@brief Advanced SDU reception flow control.
  417. *
  418. * @details Adjust the way the SoftDevice issues credits to the peer.
  419. * This may issue additional credits to the peer using an LE Flow Control Credit packet.
  420. *
  421. * @mscs
  422. * @mmsc{@ref BLE_L2CAP_CH_FLOW_CONTROL_MSC}
  423. * @endmscs
  424. *
  425. * @param[in] conn_handle Connection Handle.
  426. * @param[in] local_cid Local Channel ID of the L2CAP channel or @ref BLE_L2CAP_CID_INVALID to set
  427. * the value that will be used for newly created channels.
  428. * @param[in] credits Number of credits that the SoftDevice will make sure the peer has every
  429. * time it starts using a new reception buffer.
  430. * - @ref BLE_L2CAP_CREDITS_DEFAULT is the default value the SoftDevice will
  431. * use if this function is not called.
  432. * - If set to zero, the SoftDevice will stop issuing credits for new reception
  433. * buffers the application provides or has provided. SDU reception that is
  434. * currently ongoing will be allowed to complete.
  435. * @param[out] p_credits NULL or pointer to a uint16_t. If a valid pointer is provided, it will be
  436. * written by the SoftDevice with the number of credits that is or will be
  437. * available to the peer. If the value written by the SoftDevice is 0 when
  438. * credits parameter was set to 0, the peer will not be able to send more
  439. * data until more credits are provided by calling this function again with
  440. * credits > 0. This parameter is ignored when local_cid is set to
  441. * @ref BLE_L2CAP_CID_INVALID.
  442. *
  443. * @note Application should take care when setting number of credits higher than default value. In
  444. * this case the application must make sure that the SoftDevice always has reception buffers
  445. * available (see @ref sd_ble_l2cap_ch_rx) for that channel. If the SoftDevice does not have
  446. * such buffers available, packets may be NACKed on the Link Layer and all Bluetooth traffic
  447. * on the connection handle may be stalled until the SoftDevice again has an available
  448. * reception buffer. This applies even if the application has used this call to set the
  449. * credits back to default, or zero.
  450. *
  451. * @retval ::NRF_SUCCESS Flow control parameters accepted.
  452. * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
  453. * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
  454. * @retval ::NRF_ERROR_INVALID_STATE Invalid State to perform operation (Setup or release is
  455. * in progress for an L2CAP channel).
  456. * @retval ::NRF_ERROR_NOT_FOUND CID not found.
  457. */
  458. SVCALL(SD_BLE_L2CAP_CH_FLOW_CONTROL, uint32_t, sd_ble_l2cap_ch_flow_control(uint16_t conn_handle, uint16_t local_cid, uint16_t credits, uint16_t *p_credits));
  459. /** @} */
  460. #ifdef __cplusplus
  461. }
  462. #endif
  463. #endif // BLE_L2CAP_H__
  464. /**
  465. @}
  466. */