Registered User mNo edit summary |
Registered User mNo edit summary Tag: 2017 source edit |
||
Line 1: | Line 1: | ||
== | ==STM32WB-WBA - Connection Oriented Channel== | ||
A Connection Oriented Channel - COC allows the exchange of Bluetooth<sup>®</sup> Low Energy data at L2CAP layer without GATT layer. There is no notion of client/server, only central and peripheral.<br> | A Connection Oriented Channel - COC allows the exchange of Bluetooth<sup>®</sup> Low Energy data at L2CAP layer without GATT layer. There is no notion of client/server, only central and peripheral.<br> | ||
To set a COC logical link, it is necessary to establish first a Bluetooth<sup>®</sup> Low Energy link. Over this Bluetooth<sup>®</sup> Low Energy link, one or several COCs can be established.<br> | To set a COC logical link, it is necessary to establish first a Bluetooth<sup>®</sup> Low Energy link. Over this Bluetooth<sup>®</sup> Low Energy link, one or several COCs can be established.<br> | ||
Line 13: | Line 13: | ||
[[File:connectivity layers.png|600px|center]] | [[File:connectivity layers.png|600px|center]] | ||
|}<br> | |}<br> | ||
=== | ===General L2CAP terminology=== | ||
{|style="margin-left: auto; margin-right: auto;" | {|style="margin-left: auto; margin-right: auto;" | ||
Line 42: | Line 42: | ||
|}<br> | |}<br> | ||
== | ==L2CAP COC commands and events overview== | ||
=== | ===L2CAP COC establishment=== | ||
'''ACI_L2CAP_COC_CONNECT''' : This command sends a Credit Based Connection Request packet on the specified connection. | '''ACI_L2CAP_COC_CONNECT''' : This command sends a Credit Based Connection Request packet on the specified connection. | ||
Line 178: | Line 178: | ||
*Initial Credits are handled at application level once they have been exchanged through both previous commands.<br> | *Initial Credits are handled at application level once they have been exchanged through both previous commands.<br> | ||
=== | ===L2CAP COC data exchange=== | ||
'''ACI_L2CAP_COC_TX_DATA''' : This command sends a K-frame packet on the specified connection-oriented channel. | '''ACI_L2CAP_COC_TX_DATA''' : This command sends a K-frame packet on the specified connection-oriented channel. | ||
Line 232: | Line 232: | ||
*The application must handle '''MTU length''' received in first K-frame, '''K-frame number''', '''length of current received frame'',' and '''credits number'''.<br> | *The application must handle '''MTU length''' received in first K-frame, '''K-frame number''', '''length of current received frame'',' and '''credits number'''.<br> | ||
=== | ===L2CAP COC flow control=== | ||
'''ACI_L2CAP_COC_FLOW_CONTROL''' : This command sends a Flow Control Credit signaling packet on the specified connection-oriented channel. | '''ACI_L2CAP_COC_FLOW_CONTROL''' : This command sends a Flow Control Credit signaling packet on the specified connection-oriented channel. | ||
Line 276: | Line 276: | ||
{{Info | The application must handle credits number on transmitter and receiver side.}} | {{Info | The application must handle credits number on transmitter and receiver side.}} | ||
=== | ===L2CAP COC additional commands and events=== | ||
* '''ACI_L2CAP_COC_RECONF''' : This command sends a Credit Based Reconfigure Request packet on the specified connection. <br> | * '''ACI_L2CAP_COC_RECONF''' : This command sends a Credit Based Reconfigure Request packet on the specified connection. <br> | ||
Line 285: | Line 285: | ||
* '''ACI_L2CAP_COC_DISCONNECT_EVENT''' : This event is generated when a connection-oriented channel is disconnected following an L2CAP channel termination procedure. <br> | * '''ACI_L2CAP_COC_DISCONNECT_EVENT''' : This event is generated when a connection-oriented channel is disconnected following an L2CAP channel termination procedure. <br> | ||
== | ==L2CAP COC example== | ||
=== | ===Bluetooth<sup>®</sup> LE connection and COC establishment initiated by the central=== | ||
==== | ====On central side==== | ||
*Initiate a Bluetooth<sup>®</sup> Low Energy link: send aci_gap_create_connection | *Initiate a Bluetooth<sup>®</sup> Low Energy link: send aci_gap_create_connection | ||
*Wait for HCI_LE_CONNECTION_COMPLETE_EVENT | *Wait for HCI_LE_CONNECTION_COMPLETE_EVENT | ||
Line 295: | Line 295: | ||
Range of '''channel_index_list for the COC initiator: from 0 to 0x1F''' | Range of '''channel_index_list for the COC initiator: from 0 to 0x1F''' | ||
==== | ====On peripheral side==== | ||
*Start advertising: send aci_gap_set_discoverable | *Start advertising: send aci_gap_set_discoverable | ||
*Wait for HCI_LE_CONNECTION_COMPLETE_EVENT | *Wait for HCI_LE_CONNECTION_COMPLETE_EVENT | ||
Line 304: | Line 304: | ||
Range of '''channel_index_list for the COC peripheral: from 0x20 to 0x3F''' | Range of '''channel_index_list for the COC peripheral: from 0x20 to 0x3F''' | ||
=== | ===COC data exchange=== | ||
In following example, the purpose is to send a '''300 bytes MTU'''.<br> | In following example, the purpose is to send a '''300 bytes MTU'''.<br> | ||
As MPS is equal to 248, it takes 2 K-frames to send the entire MTU.<br> | As MPS is equal to 248, it takes 2 K-frames to send the entire MTU.<br> | ||
Line 322: | Line 322: | ||
The transmitter manages MTU fragmentation, peer device credit (Periph_Initial_Credits), and resource availability to send K-frames. | The transmitter manages MTU fragmentation, peer device credit (Periph_Initial_Credits), and resource availability to send K-frames. | ||
==== | ====On sender side==== | ||
Used ACI_L2CAP_COC_TX_DATA (Channel_Index, length, data) to send data over L2CAP. | Used ACI_L2CAP_COC_TX_DATA (Channel_Index, length, data) to send data over L2CAP. | ||
==== | ====On receiver side==== | ||
Recover the data through ACI_L2CAP_COC_RX_DATA_EVENT event. | Recover the data through ACI_L2CAP_COC_RX_DATA_EVENT event. | ||
=== | ===Example of Bluetooth<sup>®</sup> LE connection, COC establishment and data exchange=== | ||
{|style="margin-left: auto; margin-right: auto;" | {|style="margin-left: auto; margin-right: auto;" | ||
Line 346: | Line 346: | ||
|}<br> | |}<br> | ||
=== | ===Code example=== | ||
A '''STM32WB''' COC code example has been shared on STM32-Hotspot GitHub <ref>[https://github.com/stm32-hotspot/STM32WB-BLE-COC-DataTransfer STM32WB COC code example]</ref> <br> | A '''STM32WB''' COC code example has been shared on STM32-Hotspot GitHub <ref>[https://github.com/stm32-hotspot/STM32WB-BLE-COC-DataTransfer STM32WB COC code example]</ref> <br> | ||
A '''STM32WBA''' COC code example is available in STM32CubeWBA package, see BLE_SerialCom application and the following wiki page [[Connectivity:STM32WBA_Serial_Com| BLE_SerialCom]].<br> | A '''STM32WBA''' COC code example is available in STM32CubeWBA package, see BLE_SerialCom application and the following wiki page [[Connectivity:STM32WBA_Serial_Com| BLE_SerialCom]].<br> | ||
== | ==References== | ||
<references/> | <references/> | ||
<noinclude> | <noinclude> |
Revision as of 14:27, 22 April 2024
1. STM32WB-WBA - Connection Oriented Channel
A Connection Oriented Channel - COC allows the exchange of Bluetooth® Low Energy data at L2CAP layer without GATT layer. There is no notion of client/server, only central and peripheral.
To set a COC logical link, it is necessary to establish first a Bluetooth® Low Energy link. Over this Bluetooth® Low Energy link, one or several COCs can be established.
The central or the peripheral may be a COC initiator.
1.1. General L2CAP terminology
Bluetooth® LE General L2CAP terminology | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2. L2CAP COC commands and events overview
2.1. L2CAP COC establishment
ACI_L2CAP_COC_CONNECT : This command sends a Credit Based Connection Request packet on the specified connection.
L2CAP COC connect command | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
ACI_L2CAP_COC_CONNECT_EVENT : This event is generated when receiving a valid Credit Based Connection Request packet.
L2CAP COC connect event | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
ACI_L2CAP_COC_CONNECT_CONFIRM : This command sends a Credit Based Connection Response packet. It must be used upon reception of a connection request through an ACI_L2CAP_COC_CONNECT_EVENT event.
L2CAP COC connect confirm command | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
ACI_L2CAP_COC_CONNECT_CONFIRM_EVENT : This event is generated when receiving a valid Credit Based Connection Response packet.
L2CAP COC connect confirm event | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
- MTU frames are fragmented into K-frames of MPS size at application level on transmitter side.
- MTU frames are reassembled at application level on receiver side.
- Initial Credits are handled at application level once they have been exchanged through both previous commands.
2.2. L2CAP COC data exchange
ACI_L2CAP_COC_TX_DATA : This command sends a K-frame packet on the specified connection-oriented channel.
L2CAP COC Tx Data command | ||||||||
---|---|---|---|---|---|---|---|---|
|
- Note: for the first K-frame of the SDU, the information data contains the L2CAP SDU length coded on two octets followed by the K-frame information payload. For the next K-frames of the SDU, the Information data only contains the K-frame information payload.
- When the command returns the error code BLE_STATUS_INSUFFICIENT_RESOURCES (0x64), the application needs to wait for the ACI_L2CAP_COC_TX_POOL_AVAILABLE_EVENT event. This event is generated as soon as there is a free buffer available for sending K-frames.
- The application must handle MTU length, fragmentation in K-frame, length of current transmitted frame, and credits number.
ACI_L2CAP_COC_RX_DATA_EVENT : This event is generated when receiving a valid K-frame packet on a connection-oriented channel.
L2CAP COC Rx Data event | ||||||||
---|---|---|---|---|---|---|---|---|
|
- The application must handle MTU length' received in first K-frame, K-frame number, length of current received frame,' and credits number.
2.3. L2CAP COC flow control
ACI_L2CAP_COC_FLOW_CONTROL : This command sends a Flow Control Credit signaling packet on the specified connection-oriented channel.
L2CAP COC Flow control command | ||||||
---|---|---|---|---|---|---|
|
ACI_L2CAP_COC_FLOW_CONTROL_EVENT : This event is generated when receiving a valid Flow Control Credit signaling packet.
L2CAP COC Flow control command | ||||||
---|---|---|---|---|---|---|
|
2.4. L2CAP COC additional commands and events
- ACI_L2CAP_COC_RECONF : This command sends a Credit Based Reconfigure Request packet on the specified connection.
- ACI_L2CAP_COC_RECONF_CONFIRM : This command sends a Credit Based Reconfigure Response packet. It must be used upon receipt of a Credit Based Reconfigure Request through an ACI_L2CAP_COC_RECONF_EVENT event.
- ACI_L2CAP_COC_DISCONNECT : This command sends a Disconnection Request signaling packet on the specified connection-oriented channel. The ACI_L2CAP_COC_DISCONNECT_EVENT event is received when the disconnection of the channel is effective.
- ACI_L2CAP_COC_RECONF_EVENT : This event is generated when receiving a valid Credit Based Reconfigure Request packet.
- ACI_L2CAP_COC_RECONF_CONFIRM_EVENT : This event is generated when receiving a valid Credit Based Reconfigure Response packet.
- ACI_L2CAP_COC_DISCONNECT_EVENT : This event is generated when a connection-oriented channel is disconnected following an L2CAP channel termination procedure.
3. L2CAP COC example
3.1. Bluetooth® LE connection and COC establishment initiated by the central
3.1.1. On central side
- Initiate a Bluetooth® Low Energy link: send aci_gap_create_connection
- Wait for HCI_LE_CONNECTION_COMPLETE_EVENT
- Initiate a CoC connection: ACI_L2CAP_COC_CONNECT
- Wait for ACI_L2CAP_COC_CONNECT_CONFIRM_EVENT (get channel_index_list)
Range of channel_index_list for the COC initiator: from 0 to 0x1F
3.1.2. On peripheral side
- Start advertising: send aci_gap_set_discoverable
- Wait for HCI_LE_CONNECTION_COMPLETE_EVENT
- Wait for ACI_L2CAP_COC_CONNECT_EVENT
- Send ACI_L2CAP_COC_CONNECT_CONFIRM
- In hci_command_complete_event, get Channel_number and Channel_Index_List values
Range of channel_index_list for the COC peripheral: from 0x20 to 0x3F
3.2. COC data exchange
In following example, the purpose is to send a 300 bytes MTU.
As MPS is equal to 248, it takes 2 K-frames to send the entire MTU.
First K-frame contains the total SDU length in its first 2 bytes (0x2C, 0x01) little indian coded. Length field is equal to 248.
Second K-frame contains remaining data, length field is equal to 300 - (248-2) = 54 bytes.
The receiver manages its own credit (Periph_Initial_Credits), MTU length, K-frame number, and length of current received frame.
When the entire MTU is received, the receiver can update and send its new credit using ACI_L2CAP_COC_FLOW_CONTROL command.
The transmitter manages MTU fragmentation, peer device credit (Periph_Initial_Credits), and resource availability to send K-frames.
3.2.1. On sender side
Used ACI_L2CAP_COC_TX_DATA (Channel_Index, length, data) to send data over L2CAP.
3.2.2. On receiver side
Recover the data through ACI_L2CAP_COC_RX_DATA_EVENT event.
3.3. Example of Bluetooth® LE connection, COC establishment and data exchange
3.4. Code example
A STM32WB COC code example has been shared on STM32-Hotspot GitHub [1]
A STM32WBA COC code example is available in STM32CubeWBA package, see BLE_SerialCom application and the following wiki page BLE_SerialCom.
4. References