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.

Enumerations

enum  

sl_bt_l2cap_connection_result_t {

  sl_bt_l2cap_connection_result_successful = 0x0,

sl_bt_l2cap_connection_result_spsm_not_supported = 0x2,

sl_bt_l2cap_connection_result_no_resources_available = 0x4,

sl_bt_l2cap_connection_result_insufficient_authentication = 0x5,

  sl_bt_l2cap_connection_result_insufficient_authorization = 0x6, sl_bt_l2cap_connection_result_encryption_key_size_too_short = 0x7, sl_bt_l2cap_connection_result_insufficient_encryption = 0x8, sl_bt_l2cap_connection_result_invalid_source_cid = 0x9,

  sl_bt_l2cap_connection_result_source_cid_already_allocated = 0xa, sl_bt_l2cap_connection_result_unacceptable_parameters = 0xb

} | | | Defines possible result values in the responses to credit based channel connection requests. | | | | enum   | sl_bt_l2cap_command_reject_reason_t { sl_bt_l2cap_command_not_understood = 0x0, sl_bt_l2cap_signaling_mtu_exceeded = 0x1, sl_bt_l2cap_invalid_cid_request = 0x2 } | | | Describes why a request command was rejected. | | | | enum   | sl_bt_l2cap_command_code_t { sl_bt_l2cap_disconnection_request = 0x6, sl_bt_l2cap_le_connection_request = 0x14, sl_bt_l2cap_flow_control_credit = 0x16 } | | | Describes which of the request commands has been rejected. | | |

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#

enum sl_bt_l2cap_connection_result_t

Defines possible result values in the responses to credit based channel connection requests.

Enumerator

sl_bt_l2cap_connection_result_successful 

(0x0) Connection successful

sl_bt_l2cap_connection_result_spsm_not_supported 

(0x2) Connection refused - SPSM not supported

sl_bt_l2cap_connection_result_no_resources_available 

(0x4) Connection refused - no resources available

sl_bt_l2cap_connection_result_insufficient_authentication 

(0x5) Connection refused - insufficient authentication

sl_bt_l2cap_connection_result_insufficient_authorization 

(0x6) Connection refused - insufficient authorization

sl_bt_l2cap_connection_result_encryption_key_size_too_short 

(0x7) Connection refused - encryption key size too short

sl_bt_l2cap_connection_result_insufficient_encryption 

(0x8) Connection refused - insufficient encryption

sl_bt_l2cap_connection_result_invalid_source_cid 

(0x9) Connection refused - invalid Source CID

sl_bt_l2cap_connection_result_source_cid_already_allocated 

(0xa) Connection refused - Source CID already allocated

sl_bt_l2cap_connection_result_unacceptable_parameters 

(0xb) Connection refused - unacceptable parameters

sl_bt_l2cap_command_reject_reason_t#

enum sl_bt_l2cap_command_reject_reason_t

Describes why a request command was rejected.

Enumerator

sl_bt_l2cap_command_not_understood 

(0x0) Command not understood e.g., unknown command code

sl_bt_l2cap_signaling_mtu_exceeded 

(0x1) Command size has exceeded the signaling MTU size

sl_bt_l2cap_invalid_cid_request 

(0x2) An invalid CID is included in the command

sl_bt_l2cap_command_code_t#

enum sl_bt_l2cap_command_code_t

Describes which of the request commands has been rejected.

Enumerator

sl_bt_l2cap_disconnection_request 

(0x6) A disconnection request

sl_bt_l2cap_le_connection_request 

(0x14) An LE credit-based connection request

sl_bt_l2cap_flow_control_credit 

(0x16) A Flow Control Credit packet

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

ReturnsSL_STATUS_OK if successful. Error code otherwise. Events

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

ReturnsSL_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.

ReturnsSL_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.

ReturnsSL_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

ReturnsSL_STATUS_OK if successful. Error code otherwise. Events