Main Content

bleATTPDUDecode

Decode Bluetooth LE ATT PDU

    Description

    example

    [status,cfgATT] = bleATTPDUDecode(attPDU) decodes the specified Bluetooth® low energy (LE) attribute protocol data unit (ATT PDU), returning the corresponding Bluetooth LE ATT PDU configuration object, cfgATT, and the decoding status, status.

    Examples

    collapse all

    Decode two unique Bluetooth LE ATT PDUs of type 'Read by type request' and 'Error response'.

    Create a default Bluetooth LE ATT PDU configuration object.

    cfgATT = bleATTPDUConfig;

    Set the Bluetooth LE ATT PDU opcode to 'Read by type request'.

    cfgATT.Opcode = 'Read by type request'
    cfgATT = 
      bleATTPDUConfig with properties:
    
               Opcode: 'Read by type request'
          StartHandle: '0001'
            EndHandle: 'FFFF'
        AttributeType: '2800'
    
    

    Generate a Bluetooth LE ATT PDU by using the corresponding configuration object.

    attPDU = bleATTPDU(cfgATT)
    attPDU = 7x2 char array
        '08'
        '01'
        '00'
        'FF'
        'FF'
        '00'
        '28'
    
    

    Decode the generated Bluetooth LE ATT PDU. The returned status indicates decoding is successful.

    [status,cfg] = bleATTPDUDecode(attPDU)
    status = 
      blePacketDecodeStatus enumeration
    
        Success
    
    
    cfg = 
      bleATTPDUConfig with properties:
    
               Opcode: 'Read by type request'
          StartHandle: '0001'
            EndHandle: 'FFFF'
        AttributeType: '2800'
    
    

    Create another Bluetooth LE ATT PDU configuration object, this time using the name-value pairs. Set the Bluetooth LE ATT PDU opcode to 'Error response'.

    cfgATT = bleATTPDUConfig('Opcode','Error response')
    cfgATT = 
      bleATTPDUConfig with properties:
    
                 Opcode: 'Error response'
        RequestedOpcode: 'Read request'
        AttributeHandle: '0001'
           ErrorMessage: 'Invalid handle'
    
    

    Generate a Bluetooth LE ATT PDU by using the corresponding configuration object.

    attPDU = bleATTPDU(cfgATT)
    attPDU = 5x2 char array
        '01'
        '0A'
        '01'
        '00'
        '01'
    
    

    Decode the generated Bluetooth LE ATT PDU. The returned status indicates decoding is successful.

    [status,cfg] = bleATTPDUDecode(attPDU)
    status = 
      blePacketDecodeStatus enumeration
    
        Success
    
    
    cfg = 
      bleATTPDUConfig with properties:
    
                 Opcode: 'Error response'
        RequestedOpcode: 'Read request'
        AttributeHandle: '0001'
           ErrorMessage: 'Invalid handle'
    
    

    Specify a Bluetooth LE ATT PDU containing corrupted data values.

    attPDU = ['09'; '03'; '01'; '00'; '18'; '0D'];

    Decode the specified Bluetooth LE ATT PDU. The returned status indicates that the decoding failed due to mismatched attribute data lengths. In case of failed decoding, the Bluetooth LE ATT PDU configuration object displays no properties.

    [status,cfgATT] = bleATTPDUDecode(attPDU)
    status = 
      blePacketDecodeStatus enumeration
    
        MismatchAttributeDataLength
    
    
    cfgATT = 
      bleATTPDUConfig with properties:
    
    

    Input Arguments

    collapse all

    Bluetooth LE ATT PDU, specified as one of these values:

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

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

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

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

    Data Types: char | string | double

    Output Arguments

    collapse all

    Bluetooth LE ATT PDU configuration object, returned as a bleATTPDUConfig object.

    Packet decoding status, returned as a nonpositive number of the type blePacketDecodeStatus. This value represents the result of an ATT PDU decoding. Each value of this output 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
    –401UnsupportedATTOpcodeInvalid ATT opcode
    –402IncompleteATTPDUIncomplete ATT PDU
    –403InvalidATTReqOpcodeInErrorRespInvalid requested opcode in "Error Response" PDUs
    –404InvalidATTErrorCodeInvalid error code
    –405InvalidATTRxMTUInvalid received MTU
    –406 InvalidAttributeHandleRangeInvalid attribute handle range
    –407InvalidAttributeTypeInvalid attribute type flag
    –408InvalidATTExecuteWriteFlagInvalid execute write flag
    –409MismatchAttributeDataLengthLength mismatches with actual length
    –410InvalidATTDataFormat

    Invalid Data Format

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

    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