bleATTPDUDecode

Decode BLE ATT PDU

Download Required: To use bleATTPDUDecode, 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

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

Examples

collapse all

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

Create a BLE ATT PDU configuration object with default settings.

cfgATT = bleATTPDUConfig;

Change the BLE ATT PDU opcode as 'Read by type request'. View the applicable properties of the opcode '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 BLE ATT PDU using the corresponding configuration object.

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

Decode the generated BLE ATT PDU. The returned status indicates decoding is successful. View the applicable properties of the opcode 'Read by type request'.

[status, cfg] = bleATTPDUDecode(attPDU)
status = 
Success
cfg = 
  bleATTPDUConfig with properties:

           Opcode: 'Read by type request'
      StartHandle: '0001'
        EndHandle: 'FFFF'
    AttributeType: '2800'

Create another BLE ATT PDU configuration object, this time using the name-value pairs. Change the BLE ATT PDU opcode as 'Error response'. View the applicable properties of the opcode 'Error response'.

cfgATT = bleATTPDUConfig('Opcode','Error response')
cfgATT = 
  bleATTPDUConfig with properties:

             Opcode: 'Error response'
    RequestedOpcode: 'Read request'
    AttributeHandle: '0001'
       ErrorMessage: 'Invalid handle'

Generate a BLE ATT PDU using the corresponding configuration object.

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

Decode the generated BLE ATT PDU. The returned status indicates decoding is successful. View the applicable properties of the opcode 'Error response'.

[status, cfg] = bleATTPDUDecode(attPDU)
status = 
Success
cfg = 
  bleATTPDUConfig with properties:

             Opcode: 'Error response'
    RequestedOpcode: 'Read request'
    AttributeHandle: '0001'
       ErrorMessage: 'Invalid handle'

Specify a BLE ATT PDU containing corrupted data values.

attPDU = ['09'; '03'; '01'; '00'; '18'; '0D']; % Sample corrupted BLE ATT PDU

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

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

Input Arguments

collapse all

BLE 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.

Data Types: char | uint8 | uint16 | uint32 | double | string

Output Arguments

collapse all

BLE ATT PDU configuration object, returned as a bleATTPDUConfig object. This value denotes the decoded BLE ATT PDU configuration.

Packet decoding status, returned as a nonpositive number of type blePacketDecodeStatus. This value represents the result of an ATT PDU decoding. Each value of status corresponds to a member of the blePacketDecodeStatus enumeration class, which indicates the packet decoding status according to this table.

Enumeration ValueMember 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 means that the BLE ATT PDU decoding failed. If the decoding fails, object cfgATT displays no output.

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