Comprehensive BLE training

BLE ATT: Attributes, Handles, Read, Write and MTU

Understand Attribute and Handle, Read and Write and Error Response and see MTU effect with ATT packet analysis in Wireshark.

Contents
Actual view of the ESP-WROOM-32 module and its printed antenna on the development board.
The actual view of the ESP-WROOM-32 module and its printed antenna on the development board. Photo: Brian Krent; Wikimedia Commons resource; CC BY-SA 4.0. The content of the photo has not changed; A Wikimedia preview image is used. This is not a documentary photo of the LCENJ experiment.
Step 8 of 20 ways to master BLE

ATT is the basic data access language in BLE. The server has an ordered table of Attributes and the client reads or writes them with a Handle. GATT is the higher level view of this table.

Attribute and Handle

Each Attribute has a unique Handle in the Attribute table of the same server, a Type or UUID, access level and Value. Handle is a 16-bit number and specifies the place of the Attribute in the table. Handle is not guaranteed constant between firmware versions; The professional client discovers the service and does not guess the number.

Read and Write

Read Request sends a Handle and the server returns a Read Response. Write Request has success or error response, but Write Command or Write Without Response does not require ATT response for faster response. The choice of operation should be based on the importance of authentication, data rate and loss tolerance.

Error Response

If the Handle does not exist, the authorization is insufficient, or the length is invalid, the server sends an Error Response containing the Request Opcode, Handle, and Error Code. Logging these three values ​​is usually faster than guessing the cause of the error. Do not confuse security error with pairing; Characteristic may require Encryption.

MTU and fragmentation

ATT MTU is the largest PDU size in ATT. The default amount is small and both parties can negotiate a larger amount. The useful payload of each operation is a few bytes less than the MTU, because Opcode and Handle also take up space. Increasing MTU without sufficient data length and buffer does not always increase throughput.

Practice with Sniffer

Do a simple read on the mobile device. In Capture, first find the ATT Read Request, note the Handle, and then open the Read Response. Next, find the Exchange MTU and compare the agreed size with the actual length of the packets.

Read and Notification from the byte

Handle is the ID of an Attribute in the table of the same server; Do not assign a new independent table to each connection. Valid handles are in the range 0x0001 to 0xFFFF. After changing the GATT database, the client cache should also remain valid according to the protocol mechanisms.

Read Request:  0A 25 00
Read Response: 0B C4 09
Notification:  1B 25 00 C4 09

In this hypothetical example, Handle value is 0x0025 and data is 0x09C4 i.e. 2500. Just by convention in this example, 2500 is equivalent to 25.00 degrees; ATT itself does not specify the temperature unit. The Read response does not reload the Handle.

OperationOverhead inside ATTMaximum Value in MTU=23
Normal Notification / Write1 byte Opcode + 2 bytes Handle20 bytes
Read Response1 byte Opcode22 bytes

The effective MTU is the result of negotiation between the two parties. If one supports 185 and the other supports 247, the agreed value cannot exceed 185; Enlarging the MTU also does not take the place of checking the Data Length and buffer.

Question and answer article

Ask your technical question

Questions and answers are published after moderation. Authors can see their own pending drafts.

No confirmed questions have been registered for this article yet.