Main Content

bleL2CAPFrame

Generate Bluetooth LE L2CAP frame

    Description

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

    example

    l2capFrame = bleL2CAPFrame(cfgL2CAP,sdu) additionally generates a Bluetooth LE L2CAP frame for the upper-layer payload service data unit (SDU), sdu, by using the specified Bluetooth LE L2CAP configuration object. Use this syntax to generate the data frames.

    example

    Examples

    collapse all

    Create a default Bluetooth LE L2CAP configuration object.

    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
    
    

    Set the value of credits to 10.

    cfgL2CAP.Credits = 10;

    Generate a Bluetooth LE L2CAP signaling command frame from the specified 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 Bluetooth LE 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 default Bluetooth LE L2CAP configuration object.

    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
    
    

    Set the value of ATT channel identifier to '0004'.

    cfgL2CAP.ChannelIdentifier = '0004';

    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 default Bluetooth LE L2CAP configuration object. Set the value of dynamic channel identifier to '007A'.

    cfgL2CAP = bleL2CAPFrameConfig;
    cfgL2CAP.ChannelIdentifier = '007A';

    Generate a Bluetooth LE 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

    Bluetooth LE L2CAP configuration object, specified as a bleL2CAPFrameConfig object.

    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 the hexadecimal format.

    Data Types: char | double | string

    Output Arguments

    collapse all

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

    References

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

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

    Extended Capabilities

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

    Version History

    Introduced in R2019b