Main Content

bleLLDataChannelPDUDecode

Decode BLE LL data channel PDU

Download Required: To use bleLLDataChannelPDUDecode, 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,cfgLLData,LLPayload] = bleLLDataChannelPDUDecode(pdu,CRCinit) decodes a Bluetooth low energy (BLE) link layer (LL) data channel protocol data unit (PDU), returning the decoding status, status, the BLE LL data channel PDU configuration object, cfgLLData, and the upper-layer payload, LLPayload. The CRCinit denotes the initialization value of cyclic redundancy check (CRC).

example

[status,cfgLLData,LLPayload] = bleLLDataChannelPDUDecode(pdu,CRCinitName,Value) sets properties using one or more name-value pairs. Enclose each property name in quotes. For example, 'InputFormat','bits' specifies the format of input BLE LL data channel PDU in bits.

Examples

collapse all

Create a BLE LL data channel PDU configuration object by using default settings and view the corresponding applicable properties.

cfgLLData = bleLLDataChannelPDUConfig
cfgLLData = 
  bleLLDataChannelPDUConfig with properties:

                 LLID: 'Data (continuation fragment/empty)'
                 NESN: 0
       SequenceNumber: 0
             MoreData: 0
    CRCInitialization: '012345'

Initialize and set the LLID value to 'start fragment/complete' indicating the BLE LL data channel PDU with the upper-layer payload. Initialize the cyclic redundancy check (CRC) value to 'ED321C'.

cfgLLData.LLID = 'Data (start fragment/complete)';
cfgLLData.CRCInitialization = 'ED321C';
crcInit = 'ED321C'; % CRC initialization value

Generate the BLE LL data channel PDU with upper-layer payload given in hexadecimal octets.

pdu = bleLLDataChannelPDU(cfgLLData,'030004000A0100');

Decode the generated BLE LL data channel PDU. The returned status indicates decoding is successful. View the output of 'status', 'cfgLLData' and 'llPayload'.

[status, cfgLLData, llPayload] = bleLLDataChannelPDUDecode(pdu,crcInit)
status = 
Success
cfgLLData = 
  bleLLDataChannelPDUConfig with properties:

                 LLID: 'Data (start fragment/complete)'
                 NESN: 0
       SequenceNumber: 0
             MoreData: 0
    CRCInitialization: '012345'

llPayload = 7x2 char array
    '03'
    '00'
    '04'
    '00'
    '0A'
    '01'
    '00'

Specify a sample BLE LL data channel PDU in octets.

pdu = '030C00010000060000000A000000FCD2A6'; % Sample PDU in octets

Initialize the CRC value.

crcInit = 'ED323C'; % CRC initialization value

Decode the specified BLE LL data channel PDU by specifying 'InputFormat' to 'octets'. The specified PDU is a control PDU. The returned status indicates decoding is successful. View the output of 'status', 'cfgLLData' and 'llPayload'. You can see the decoded configuration of the specified PDU in the 'ControlConfig' property of 'cfgLLData'.

[status, cfgLLData, llPayload] = bleLLDataChannelPDUDecode(...
    pdu, crcInit, ...
    'InputFormat', ...
    'octets')
status = 
Success
cfgLLData = 
  bleLLDataChannelPDUConfig with properties:

                 LLID: 'Control'
                 NESN: 0
       SequenceNumber: 0
             MoreData: 0
    CRCInitialization: '012345'
        ControlConfig: [1x1 bleLLControlPDUConfig]

llPayload =

  1x0 empty char array

Specify a BLE LL data channel PDU containing corrupted data values. Initialize the CRC value.

pdu = '040C00010000060000000A00'; % Sample corrupted PDU
crcInit = 'CD3234'; % CRC initialization value

Decode the specified BLE LL data channel PDU. The returned status indicates that the decoding failed due to the corrupted BLE LL data channel PDU. If the decoding fails, the reason is indicated and the BLE LL data channel PDU configuration object, 'cfgLLData', displays no properties.

[status, cfgLLData, llPayload] = bleLLDataChannelPDUDecode(...
    pdu, crcInit, ...
    'InputFormat', ...
    'octets')
status = 
CRCFailed
cfgLLData = 
  bleLLDataChannelPDUConfig with properties:

llPayload =

  1x0 empty char array

Input Arguments

collapse all

BLE LL data channel PDU, 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.

  • Binary vector — This vector represents BLE LL data channel PDU bits.

Data Types: char | string | double

CRC initialization value, specified as a 6-element character vector or a string scalar representing 3-octet hexadecimal value.

Data Types: char | string

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: [status,cfgLLData,LLPayload] = bleLLDecodeDataChannelPDU('pdu','CRCInit','InputFormat','octets')

BLE LL data channel PDU format, specified as 'bits' or'octets'. When specified as 'bits', InputFormat is a binary vector. When specified as 'octets', InputFormat is a numeric vector representing octets in decimal format or a character array or a string scalar representing octets in hexadecimal format.

Data Types: char | string | double

Output Arguments

collapse all

BLE LL data channel PDU decoding status, returned as a nonpositive number of type blePacketDecodeStatus. This value represents the result of a BLE LL data channel PDU decoding. Each value of status corresponds to a member of the blePacketDecodeStatus enumeration class, which indicates the packet decoding status as listed in this table.

Enumeration ValueMember of Enumeration ClassDecoding Status
0SuccessPacket decoding succeeded
-1 CRCFailedLink Layer PDU is corrupted
–2LLPDULengthMismatchLength field does not match with actual PDU length
–3InvalidLLSlaveLatencyInvalid slave latency
–4InvalidLLConnectionTimeoutInvalid connection timeout
–5InvalidLLWindowSizeInvalid window size
–6InvalidLLWindowOffsetInvalid window offset
–7InvalidLLConnectionIntervalInvalid connection interval
–8InvalidLLChannelMapInvalid channel map
-101IncompleteLLDataChannelPDUInsufficient octets in data channel PDU
-102InvalidLLIDInvalid LLID
-103UnsupportedLLOpCodeUnsupported opcode
-104InvalidLLErrorCodeInvalid error code
-105InvalidBluetoothVersionInvalid version
-106ExpectedNonZeroPayloadNonzero payload expected
-107MICNotSupportedPayload contains MIC

An enumeration value other than 0 means that the BLE LL data channel PDU decoding failed. If decoding fails, object cfgLLData displays no output.

BLE LL data channel configuration object, returned as a bleLLDataChannelPDUConfig object. This value represents the decoded BLE LL data channel PDU configuration.

Upper-layer payload, returned as a character array where each row is the hexadecimal representation of an octet.

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

Introduced in R2019b