Main Content

bleL2CAPFrame

Generate BLE L2CAP frame

Download Required: To use bleL2CAPFrame, first download Communications Toolbox™ Library for the Bluetooth® Protocol. For more information, see Get and Manage Add-Ons. Alternatively, see Communications Toolbox Library for the Bluetooth Protocol File Exchange.

Description

example

L2CAPFrame = bleL2CAPFrame(cfgL2CAP) generates a Bluetooth low energy (BLE) logical link control and adaptation protocol (L2CAP) frame, L2CAPFrame, for a given BLE L2CAP configuration object, cfgL2CAP. Use this syntax to generate the signaling frames.

example

L2CAPFrame = bleL2CAPFrame(cfgL2CAP,SDU) generates a BLE L2CAP frame, L2CAPFrame, for a given BLE L2CAP configuration object cfgL2CAP and the upper-layer payload service data unit (SDU), SDU. Use this syntax to generate the data frames.

Examples

collapse all

Create a BLE L2CAP configuration object, 'cfgL2CAP', and view the corresponding default properties.

cfgL2CAP = bleL2CAPFrameConfig
cfgL2CAP = 
  bleL2CAPFrameConfig with properties:

          ChannelIdentifier: '0005'
                CommandType: 'Credit based connection request'
           SignalIdentifier: '01'
    SourceChannelIdentifier: '0040'
                      LEPSM: '001F'
        MaxTransmissionUnit: 23
          MaxPDUPayloadSize: 23
                    Credits: 1

Change the value of credits to 10.

cfgL2CAP.Credits            = 10;

Generate a BLE L2CAP signaling command frame from the corresponding configuration object.

l2capFrame = bleL2CAPFrame(cfgL2CAP)
l2capFrame = 18x2 char array
    '0E'
    '00'
    '05'
    '00'
    '14'
    '01'
    '0A'
    '00'
    '1F'
    '00'
    '40'
    '00'
    '17'
    '00'
    '17'
    '00'
    '0A'
    '00'

Generate two unique BLE L2CAP data frames: one with SDU from the attribute protocol (ATT) layer as '0A0100' and the other with an upper-layer payload SDU,'0A01E2D3'.

Create a BLE L2CAP configuration object, 'cfgL2CAP', and view the default properties.

cfgL2CAP = bleL2CAPFrameConfig
cfgL2CAP = 
  bleL2CAPFrameConfig with properties:

          ChannelIdentifier: '0005'
                CommandType: 'Credit based connection request'
           SignalIdentifier: '01'
    SourceChannelIdentifier: '0040'
                      LEPSM: '001F'
        MaxTransmissionUnit: 23
          MaxPDUPayloadSize: 23
                    Credits: 1

Change the value of channel identifier to '0004'.

cfgL2CAP.ChannelIdentifier = '0004'; % Channel identifier for ATT

Generate a BLE L2CAP data frame from 'cfgL2CAP', specifying the upper-layer payload SDU from the ATT layer as '0A0100'.

l2capFrame = bleL2CAPFrame(cfgL2CAP,"0A0100")
l2capFrame = 7x2 char array
    '03'
    '00'
    '04'
    '00'
    '0A'
    '01'
    '00'

Create another BLE L2CAP configuration object, 'cfgL2CAP', with default properties. Set the value of channel identifier to '007A'.

cfgL2CAP = bleL2CAPFrameConfig;
cfgL2CAP.ChannelIdentifier = '007A'; % Dynamic channel identifier

Generate a BLE L2CAP data frame from 'cfgL2CAP', specifying the upper-layer payload SDU as '0A01E2D3'.

l2capFrame = bleL2CAPFrame(cfgL2CAP,['0A'; '01'; 'E2'; 'D3'])
l2capFrame = 10x2 char array
    '06'
    '00'
    '7A'
    '00'
    '04'
    '00'
    '0A'
    '01'
    'E2'
    'D3'

Input Arguments

collapse all

BLE L2CAP configuration object, specified as a bleL2CAPFrameConfig object. The function uses this object to configure the BLE L2CAP frame and its applicable properties.

Upper-layer payload, specified as one of these types:

  • Character vector — This vector represents octets in hexadecimal format.

  • String scalar — This scalar represents octets in hexadecimal format.

  • Numeric vector of elements in the range [0, 255] — This vector represents octets in decimal format.

  • n-by-2 character array — Each row represents an octet in hexadecimal format.

Data Types: char | double | string

Output Arguments

collapse all

Generated BLE L2CAP frame, returned as a character array. Each row of the array represents an octet in hexadecimal format. This value represents the output BLE L2CAP frame.

References

[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed November 22, 2019. https://www.bluetooth.com/.

[2] Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification." Version 5.1. https://www.bluetooth.com/.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2019b