L2CAP Connection Oriented Channels
L2CAP Connection Oriented Channels.
Modules | |
sl_bt_evt_l2cap_le_channel_open_request | |
Indicates that an LE credit-based connection request on a Bluetooth connection is received. | |
sl_bt_evt_l2cap_le_channel_open_response | |
Indicates that an LE credit-based connection response is received. | |
sl_bt_evt_l2cap_channel_data | |
Indicates that data is received on a channel. | |
sl_bt_evt_l2cap_channel_credit | |
Indicates that flow control credits are received on a channel informing that the peer channel endpoint is capable of receiving more data. | |
sl_bt_evt_l2cap_channel_closed | |
Indicates that a credit-based logical channel is closed by the local or peer device. | |
sl_bt_evt_l2cap_command_rejected | |
Indicates that the peer device rejected a command. | |
Functions | |
sl_status_t | sl_bt_l2cap_open_le_channel (uint8_t connection, uint16_t spsm, uint16_t max_sdu, uint16_t max_pdu, uint16_t credit, uint16_t *cid) |
sl_status_t | sl_bt_l2cap_send_le_channel_open_response (uint8_t connection, uint16_t cid, uint16_t max_sdu, uint16_t max_pdu, uint16_t credit, uint16_t errorcode) |
sl_status_t | sl_bt_l2cap_channel_send_data (uint8_t connection, uint16_t cid, size_t data_len, const uint8_t *data) |
sl_status_t | sl_bt_l2cap_channel_send_credit (uint8_t connection, uint16_t cid, uint16_t credit) |
sl_status_t | sl_bt_l2cap_close_channel (uint8_t connection, uint16_t cid) |
Detailed Description
L2CAP Connection Oriented Channels.
The commands and events in this class provide Logical Link Control and Adaptation Protocol (L2CAP) credit-based logical channels.
An L2CAP credit-based logical channel is a logical link identified by a channel identifier (the cid
parameter in the commands and events of this API class). These channels use a credit-based flow control mechanism. The credit can be configured at the channel opening and later dynamically updated on the channel.
The Simplified Protocol/Service Multiplexer (SPSM) of a channel specifies the protocol or services the channel implements. It can be a value for a fixed service assigned by the Bluetooth SIG or a dynamically allocated value and used with services defined in the GATT Server. The dynamically assigned value may be used to support multiple implementations of a particular protocol. See the Bluetooth core specification for more details. The application specifies the SPSM value in a channel open request in the spsm
parameter of the sl_bt_l2cap_open_le_channel command.
Each of the local and peer channel endpoints must specify the maximum Service Data Unit (SDU) size (the 'MTU' field of the L2CAP packets in the Bluetooth Core specification) that it can receive on the channel. The application specifies the maximum Service Data Unit size (the max_sdu
parameter in commands and events) of the local channel endpoint.
Each channel endpoint has a maximum PDU payload Size that the L2CAP layer can receive in a single data packet on the channel. The maximum PDU payload size supported by the stack for local channel endpoints is 252 bytes, which is the maximum data length the sl_bt_evt_l2cap_channel_data event can support. The application specifies the max PDU payload size (the max_pdu
parameter in commands and events). Additionally, the application is responsible for handling the segmentation from SDU to PDU and reassembly from PDU to SDU.
Enumeration Type Documentation
◆ sl_bt_l2cap_connection_result_t
Defines possible result values in the responses to credit based channel connection requests.
◆ sl_bt_l2cap_command_reject_reason_t
Describes why a request command was rejected.
◆ sl_bt_l2cap_command_code_t
Function Documentation
◆ sl_bt_l2cap_open_le_channel()
sl_status_t sl_bt_l2cap_open_le_channel | ( | uint8_t | connection, |
uint16_t | spsm, |
||
uint16_t | max_sdu, |
||
uint16_t | max_pdu, |
||
uint16_t | credit, |
||
uint16_t * | cid |
||
) |
Create and configure an L2CAP channel on a Bluetooth connection using the LE credit based connection request packet. Event sl_bt_evt_l2cap_le_channel_open_response will be received after the peer device responded to the request.
- Parameters
-
[in] connection
The connection handle [in] spsm
The protocol/services implemented by the local channel endpoint [in] max_sdu
The Maximum Service Data Unit size the local channel endpoint can accept
Range: 23 to 65533.
[in] max_pdu
The maximum PDU payload size the local channel endpoint can accept
Range:23 to 252.
[in] credit
The initial credit value of the local channel endpoint, i.e., number of PDUs the peer channel endpoint can send [out] cid
The channel identifier
- Returns
- SL_STATUS_OK if successful. Error code otherwise.
Events
- sl_bt_evt_l2cap_le_channel_open_response - Triggered when an LE credit based connection response has been received in response to this command.
- sl_bt_evt_l2cap_channel_closed - Triggered when a LE credit based connection response has not been received within 30 seconds after this command has been issued.
◆ sl_bt_l2cap_send_le_channel_open_response()
sl_status_t sl_bt_l2cap_send_le_channel_open_response | ( | uint8_t | connection, |
uint16_t | cid, |
||
uint16_t | max_sdu, |
||
uint16_t | max_pdu, |
||
uint16_t | credit, |
||
uint16_t | errorcode |
||
) |
Send an LE credit-based connection response to an LE credit-based connection request received in the sl_bt_evt_l2cap_le_channel_open_request event. Result code sl_bt_l2cap_connection_result_successful in errorcode
implies that the logical channel is established and data can be sent or received on the channel. Other parameters in this command are ignored if errorcode
indicates that the request was rejected.
- Parameters
-
[in] connection
The connection handle [in] cid
The channel identifier [in] max_sdu
The Maximum Service Data Unit size the local channel endpoint can accept
Range: 23 to 65533.
[in] max_pdu
The maximum PDU payload size the local channel endpoint can accept
Range:23 to 252.
[in] credit
The initial credit value of the local channel endpoint, i.e., number of PDUs that the peer channel endpoint can send [in] errorcode
Enum sl_bt_l2cap_connection_result_t.
An L2CAP error code as the outcome of the connection request
- Returns
- SL_STATUS_OK if successful. Error code otherwise.
◆ sl_bt_l2cap_channel_send_data()
sl_status_t sl_bt_l2cap_channel_send_data | ( | uint8_t | connection, |
uint16_t | cid, |
||
size_t | data_len, |
||
const uint8_t * | data |
||
) |
Send data to the peer channel endpoint on a Bluetooth connection. If the SDU length is larger than max_pdu size or 250 bytes, the application should fragment the SDU into multiple K-frames and call this command once for each K-frame.
The first K-frame of the SDU should start with 2 bytes of SDU length followed with payload. Therefore, the first K-frame contains PDU length minus 2 bytes of the actual payload. All subsequent K-frames of the same SDU contain PDU length of the payload. The sum of the payload lengths for K-frames should be equal to the specified SDU length.
- Parameters
-
[in] connection
The connection handle [in] cid
The channel identifier [in] data_len
Length of data in data
[in] data
Data to be sent. The data length must not be greater than the lesser of the peer channel endpoint max_pdu and 252 bytes, which is the maximum data length this command can send.
- Returns
- SL_STATUS_OK if successful. Error code otherwise.
◆ sl_bt_l2cap_channel_send_credit()
sl_status_t sl_bt_l2cap_channel_send_credit | ( | uint8_t | connection, |
uint16_t | cid, |
||
uint16_t | credit |
||
) |
Send flow control credits to the peer channel endpoint indicating that the local channel endpoint is capable of receiving more data.
- Parameters
-
[in] connection
The connection handle [in] cid
The channel identifier [in] credit
The credit value, i.e., the additional number of PDUs the peer channel endpoint can send
Range: 1 to 65535.
- Returns
- SL_STATUS_OK if successful. Error code otherwise.
◆ sl_bt_l2cap_close_channel()
sl_status_t sl_bt_l2cap_close_channel | ( | uint8_t | connection, |
uint16_t | cid |
||
) |
Send a disconnect request to close a credit-based logical channel.
- Parameters
-
[in] connection
The connection handle [in] cid
The channel identifier
- Returns
- SL_STATUS_OK if successful. Error code otherwise.
Events
- sl_bt_evt_l2cap_channel_closed - Triggered when an credit-based logical channel is closed in response to this command.