Bluetooth att Introduction

Source: Internet
Author: User
Tags error code prepare readable uuid

ATT, attribute Protocol, protocol for discovering, reading, and writing to-end devices (for BLE devices) 1 Introduction

ATT allows a device to provide a set of attributes with associated values as a server
Let the device as a client to discover, read, write these attributes, and the server can actively notify the client

The ATT defines two roles: server and Client

The attributes in the ATT contain the following three contents
-Attribute Type: Defined by UUID (universally Unique IDentifier)
-Attribute Handle: Used to access Attribute Value
-A set of Permissions: Controls whether the attribute is readable, writable, and whether the attribute value is sent via an encrypted link

One device can have both server and client
and a server can support multiple client 2 details

The client discovers Attribute Handles 2.1 Attribute Type by using the att PDUs (Protocol Data Unit)

The Attribute type is specified by the UUID, and the UUID is a 128-bit value

In the process of use, in order to improve efficiency, using the 16-bits Attribute UUID
128-bit UUID = 16-bit Attribute uuid*2^96 + bluetooth_base_uuid
Bluetooth_base_uuid = 00000000-0000-1000-8000-00805F9B34FB

A simpler approach is as follows (XXXX stands for 16-16-bit UUID)
0000xxxx-0000-1000-8000-00805f9b34fb

Tip:16-bit Attribute UUIDs with SDP 16-bit UUIDs using the same namespace 2.2 Attribute Handle

Attribute handle is a unique and non-zero 16-bit value assigned by the server
0x0000: Reserved
0xFFFF: Max Attribute Handle 2.3 Attribute Handle Grouping

Grouping is a set of attributes defined by a high-level protocol that precedes other attribute groups
The customer can request the first and last handle associated with the attribute group 2.4 Attribute Value

Attribute value is a eight-bit group (8 or variable in length)
When the property value is too long, it can be sent through multiple PDUs

When transmitting attribute values in a request, a response, a notification or an indication,
The attribute value length is not sent in any field of the PDU.

The length of a variable length field in the PDU was implicitly given by the length of the packet that carries this PDU.
This implies:
A) Only one attribute value can being placed in a single request, response, notification or indication
Unless the attribute values has lengths known by both the server and client, as defined by the attribute type.
b) This attribute value would always be the only variable length field of a request, response, notification or indication.
c) the bearer protocol (e.g. L2cap) preserves datagram boundaries. 2.5 Attribute Permissions

Attributes have a set of permission Values associated with them.

The permission for a given property is defined by a high-level protocol and is not visible to the ATT

When accessing a security attribute requires an authenticated link, and the client does not have sufficient permissions
The server responds with an error Code (insufficient authentication)
After the client receives the error code, it should attempt to authenticate the link, and the security property can be accessed after success

When accessing a security attribute requires an encrypted link, and the link is not encrypted
The server responds to an error Response (insufficient encryption)
The client should attempt to encrypt the link after receiving the error response, and then access the security property after it succeeds

An encrypted link is required when accessing a security attribute
The link is encrypted, but the encryption key size is too short for the required security level
The server responds with an error Code (insufficient encryption Key Size)
After the client receives the error response, it should attempt to encrypt the link using a longer key size, which can then be accessed after the security attribute has been successfully

Attribute permissions is composed of the following three permissions
-Access Permissions: Determines whether the client can read, write property values
~ Readable
~ Writable
~ Readable and writable
-Authentication Permissions: Determine if a certified physical link is required (authenticated physical link)
~ Authentication Required
~ No Authentication Required
-Authorization permssions: Determines whether the client needs authorization before accessing the attribute value
~ Authorization Required
~ No Authorization Required 2.6 control-point Attribute

Unreadable, writable, and notified (indicated) properties are called Control-point Attribute

High-level protocols can use this property to enable device-specific processes, such as commands or instructions for a given procedure on a device, to complete 2.7 Protocol Methods

ATT uses protocol methods to discover, read, write, notify, and indicate attributes
Methods can be divided into the following types
-Request
-Response
-Command
-Notification
-Indication
-Confirmation

Some att pdus contain a certified signature (authentication Signature)
Allow PDU send side to not require encryption

These methods and symbol bits are called opcode 2.8 exchanging MTU Size

ATT_MTU defines the maximum number of packets between the client and server
Its default value is defined by a high-level protocol

Client and server can exchange maximum packets through Exchange MTU Request and Response PDUs
The communication is then performed using the minimum value in the interchange value

Both server and client devices should use the same client Rx MTU and Server Rx MTU

Each att bearer has its ATT_MTU
When a device has multiple att bearer, the att_mtu of different att bearer may be different 2.9 Long Attribute Value

The maximum size of the property that can be sent in a single packet is [att_mtu–1] octets
Contains at least attribute Opcode in a attribute PDU

Property value is greater than [Att_mtu-1] octets property is called Long Attribute

For long Attribute
-Use the Read Blob request to read the entire property (Attribute > [att_mtu-1] octets)
-Write the entire property using prepare write request and Execute write request (Attribute > [att_mtu-3] octets)

ATT cannot determine if the property value is greater than [ATT_MTU] octets
But the high-level protocol can tell

The maximum attribute value is octets 2.10 Atomic Operation

Server should treat each request or command of the client as an atomic operation that is not affected by the image
If a link is disconnected for some reason, the high-level protocol should be responsible for the property's worth of modification

Long Attribute cannot be read and written by a single atomic operation 3 Attribute PDU

There are six types of Attribute PDUs
-Requests:client->server, request a response
-Responses:server->client, responding to requests.
-Commands:client->server, command
-Notifications:server->client, service-side notification
-Indications:server->client, Request confirmation
-Confirmations:client->server, Ind Confirmation

The server can handle at least the following requests
-Find Information Request
-Read Reques

The Attribute PDU format is as follows


===authentication Signature flag===
-1:PDU contains authentication Signature (octets), x 13
-0:PDU does not contain authentication Signature, X is 1
When the attribute PDU contains authentication signature, the PDU should not be transmitted over an encrypted link

===command flag===
-1:PDU as a command

Note: Only the write command may contain a authentication Signature

The ATT is a sequential Protocol, which means that the response should be answered before the next action is performed.
Att sees Request-response and indication-confirmation pair as a single transaction (Transaction) 4 Attribute Protocol PDU 4.1 Error handing

The Error response is used to declare that a given request cannot be completed and gives the reason


Request Opcode in error: An error occurred attribute Opcode
Attribute Handle in Error:attribute opcode corresponding Attribute Handle, if none or opcode not supported, use 0x0000
Error Code: One of the following figure values, which is considered unknown if client cannot understand it (as defined in the updated version of ErrorCode)


4.2 MTU Exchange 4.2.1 Exchange MTU Request

The client uses the MTU Exchange request to tell the supported maximum receive MTU size
Requests the server to respond to the maximum receive MTU size supported by the server


Client Rx mtu>= Default Att_mtu

The request is sent only once in a connection, and the client Rx MTU should be set to the maximum value that the client can receive the ATT PDU 4.2.2 Exchange MTU Response

Server uses Exchange MTU response to respond to Exchange MTU Request from client


Server Rx mtu>= Default Att_mtu

The server Rx MTU should be set to the maximum value that the server can receive ATT PDU

When REQ-RSP is complete, both the server and the client set the ATT_MTU to the client Rx MTU and the smaller value in the Server Rx MTU

ATT_MTU Effective Time:
-Server:response after sending, other ATT PDU before sending
-Client:response after receiving, other ATT PDU before sending

When any of these values is less than the default ATT_MTU size, you should set ATT_MTU to the default value when this value is not considered correct

When a device is both client and server, the ATT_MTU value should be the same for different roles (detailed rules can be see specification) 4.3 find information 4.3.1 find information Request

Find Information request is used to get the type associated with attribute handles
Client uses this request to discover a list of Attribute-type on the server


Read all attributes
-Starting handle:0x0001
-Ending HANDLE:0XFFFF

Rules
-Starting Handle <= ending Handle:response PDU or error Response<attribute not found>
-Starting Handle > ending handle:server response error Response<invalid handle>
-Starting Handle = 0x0000:server response error Response<invalid handle>

The server should not respond to the error code of the following error Response
-<insufficient authentication>
-<insufficient authorization>
-<insufficient Encryption Key size>
-<application error> 4.3.2 Find information Response


The Response PDU should contain the full handle-uuid
This means that handle-uuid should be in a single response message.
At the same time response PDU responds in ascending order of handle

The format parameter has two possible values



When a response PDU is unable to load all the Handle-uuid pairs
The client launches another find information Request with the new starting handle to get the information that is not responding 4.3.3 Find by Type Value request

The req is used to obtain Attribute Handles for the specified 16-bit UUID Attribute type and Attribute value


Read all attributes
-Starting handle:0x0001
-Ending HANDLE:0XFFFF

Other rules similar to find information request 4.3.4 Find by Type Value Response


Handles Information list contains one or more handle information lists


Rules similar to find information response 4.4 Reading Attributes 4.4.1 Read by Type Request

Read by Type request is used to obtain attribute Values (client-known attribute Type but unknown attribute Handle)


Find all attributes
-Starting handle:0x0001
-Ending HANDLE:0XFFFF

TIP: All attribute type is compared by 128-bit uuid, even if the 16-bit UUID is provided

Rules
-Starting Handle <= ending Handle:response PDU or error Response<attribute not found>
-Starting Handle > ending handle:server response error Response<invalid handle>
-Starting Handle = 0x0000:server response error Response<invalid handle>

The length of the attribute type should be the same in this message, or another request will need to be re-initiated

When the client is unreachable for security reasons, the server should respond to the error Response
-<insufficient authentication>
-<insufficient authorization>
-<insufficient Encryption Key size>
-<insufficient encryption>

Some other permissions cause a failure to read when the response
-<read not permitted> 4.4.2 Read by Type Response


Attribute Data Field field is Attribute handle-value list


Read by Type response contains the full Handle-value pair
This means that handle-value should be in a single response message.
At the same time response PDU responds in ascending order of handle

The maximum length of the handle-value pair is 255 octets, which is the long parameter
So the largest attribute value is (Length-2) =253 octets

In the Handle-value list of responses
-Attribute Value > (att_mtu-4)/253 octets section: Client re-requests read Blob request for
-Attribute Value <= (att_mtu-4)/253 octets part: Response 4.4.3 Read Request in Rsp PDU

Read Request for attribute Value


Attribute handle should be a valid handle
Otherwise the response error Response<invalid handle>

Unable to access the response due to security issues with the read by Type Request

4.4.4 Read Response


When attribute value is longer than (ATT_MTU-1), the former (att_mtu-1) octets should be responded
Client initiates a read Blob request to get the rest of the data
4.4.5 Read Blob Request


The attribute Value used to obtain the handle specified offset

NOTICE: Too much content, the author can not be described, only give a summary, detailed information please refer to the specification, the same 4.4.6 Read Blob Response


When value offset is equal to the length of attribute value, the response 0
When attribute value is greater than (value Offset + att_mtu-1)
Response attribute value starts with value offset (att_mtu-1) octets 4.4.7 Read multiple Request

The value that is used to request two or more property sets


4.4.8 Read multiple Response


4.4.9 Read by Group Type Request

Property value used to request a known attribute type


4.4.10 Read by Group Type Response


The Attribute data format is as follows


4.5 Writing Attributes 4.5.1 Write Request

Used to write property values


4.5.2 Write Response

Used to notify client that the property value has been successfully written


4.5.3 Write Command

Used to write attribute values, usually control-point Attribute

4.5.4 signed Write Command

Used to write attribute values, including a authentication Signature, usually Control-point Attribute


4.6 Queued writes

To queue Multiple property value writes in a FIFO manner, and then perform an atomic operation in 4.6.1 Prepare write Request


4.6.2 Prepare Write Response


4.6.3 Execute Write Request


4.6.4 Execute Write Response


4.7 Server initiated 4.7.1 Handle Value Notification

Server can send a notification of attribute value to the client at any time


4.7.2 Handle Value Indication

Server can send an indication of attribute value (indication)


4.7.3 Handle Value Confirmation

Used to respond to handle Value indication, confirming that IND has received


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.