bleATTPDUDecode
Decode Bluetooth LE ATT PDU
Description
Examples
Decode Bluetooth LE ATT PDUs
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'
Decode Corrupted Bluetooth LE ATT PDU
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
attPDU
— Bluetooth LE ATT PDU
character vector of octets in hexadecimal format | string scalar of octets in hexadecimal format | numeric vector of elements in range [0, 255] | n-by-2 character array
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
cfgATT
— Bluetooth LE ATT PDU configuration object
bleATTPDUConfig
object
Bluetooth LE ATT PDU configuration object, returned as a bleATTPDUConfig
object.
status
— Packet decoding status
nonpositive integer
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
status | Member of Enumeration Class | Decoding Status |
0 | Success | Packet decoding succeeded |
–401 | UnsupportedATTOpcode | Invalid ATT opcode |
–402 | IncompleteATTPDU | Incomplete ATT PDU |
–403 | InvalidATTReqOpcodeInErrorResp | Invalid requested opcode in "Error Response" PDUs |
–404 | InvalidATTErrorCode | Invalid error code |
–405 | InvalidATTRxMTU | Invalid received MTU |
–406 | InvalidAttributeHandleRange | Invalid attribute handle range |
–407 | InvalidAttributeType | Invalid attribute type flag |
–408 | InvalidATTExecuteWriteFlag | Invalid execute write flag |
–409 | MismatchAttributeDataLength | Length mismatches with actual length |
–410 | InvalidATTDataFormat | 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
See Also
Functions
Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)