Main Content

bleL2CAPFrameDecode

Decode Bluetooth LE L2CAP frame

Since R2019b

    Description

    example

    [status,cfgL2CAP,SDU] = bleL2CAPFrameDecode(L2CAPFrame) decodes the specified Bluetooth® low energy (LE) logical link control and adaptation protocol (L2CAP) frame, L2CAPFrame. The function returns the decoding status, status, the corresponding Bluetooth LE L2CAP configuration object, cfgL2CAP, and the upper-layer payload service data unit (SDU), SDU.

    Examples

    collapse all

    Create a default Bluetooth LE L2CAP configuration object. Set the value of channel identifier to '0004'.

    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
    
    
    cfgL2CAP.ChannelIdentifier = '0004';

    Generate a Bluetooth LE L2CAP data frame from 'cfgL2CAP', specifying the upper-layer payload SDU from attribute protocol (ATT) layer as '0A0100'.

    L2CAPFrame = bleL2CAPFrame(cfgL2CAP,"0A0100");

    Decode the generated Bluetooth LE L2CAP data frame. The returned status indicates decoding was successful.

    [status,cfgL2CAP,SDU] = bleL2CAPFrameDecode(L2CAPFrame)
    status = 
      blePacketDecodeStatus enumeration
    
        Success
    
    
    cfgL2CAP = 
      bleL2CAPFrameConfig with properties:
    
        ChannelIdentifier: '0004'
    
    
    SDU = 3x2 char array
        '0A'
        '01'
        '00'
    
    

    Specify a Bluetooth LE L2CAP frame containing corrupted data values.

    l2capFrame = ['090005000107040060005000'];

    Decode the specified Bluetooth LE L2CAP frame. The returned status indicates that the decoding failed due to the corrupted input L2CAP frame. If the decoding fails, the output displays the reason of failure and the object displays no properties.

    [status,cfgL2CAP,sdu] = bleL2CAPFrameDecode(l2capFrame)
    status = 
      blePacketDecodeStatus enumeration
    
        MismatchL2CAPHeaderLength
    
    
    cfgL2CAP = 
      bleL2CAPFrameConfig with properties:
    
    
    sdu =
    
      1x0 empty char array
    

    Input Arguments

    collapse all

    Bluetooth LE L2CAP frame, specified as one of these values:

    • 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

    Packet decoding status, returned as a nonpositive integer of type blePacketDecodeStatus. This value represents the result of decoding a Bluetooth LE L2CAP frame. Each value of status corresponds to a member of the blePacketDecodeStatus enumeration class, which indicates the packet decoding status according to this table.

    Value of statusMember of Enumeration ClassDecoding Status
    0SuccessPacket decoding succeeded
    –301InvalidL2CAPConnectionIntervalRangeInvalid connection intervals
    –302InvalidL2CAPPeripheralLatencyInvalid Peripheral latency
    –303InvalidLECreditsInvalid low energy (LE) credits
    –304L2CAPSegmentationUnsupportedSegmentation is not supported
    –305MismatchL2CAPHeaderLengthLength mismatches with actual length
    –306 IncompleteL2CAPDataFrameL2CAP data frame is not sufficient to decode
    –307InvalidL2CAPChannelIdentifierInvalid L2CAP channel identifier
    –308InvalidL2CAPCommandInvalid L2CAP command code
    –309InvalidL2CAPCommandRejectReasonInvalid command reject reason code
    –310InvalidL2CAPParameterUpdateResultInvalid parameters update result
    -311InvalidL2CAPConnectionResultInvalid connection result code
    -312IllegalL2CAPSignalIdentifierIllegal signal identifier in L2CAP
    -313InvalidL2CAPConnectionIntervalMinimumInvalid interval minimum
    -314InvalidL2CAPConnectionIntervalMaximumInvalid interval maximum
    -315InvalidL2CAPConnectionTimeoutInvalid connection timeout
    -316 InvalidLEPSMInvalid LE protocol/service multiplexer
    -317InvalidL2CAPChannelMTUInvalid maximum transmission unit
    -318InvalidL2CAPChannelMPSInvalid maximum PDU payload size
    -319InvalidL2CAPSDULengthInvalid SDU length
    -320MismatchL2CAPSignalFrameLengthLength mismatches with actual length
    -321IncompleteL2CAPSignalFrameL2CAP signal frame is not valid or not sufficient

    An enumeration value other than 0 implies failed Bluetooth LE ATT PDU decoding. If the decoding fails, the cfgATT object displays no output.

    Bluetooth LE L2CAP frame configuration object, returned as a bleL2CAPFrameConfig object.

    Upper-layer payload, returned as a character array. Each row of the array represents an octet in hexadecimal format.

    Data Types: char | string

    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