Bluetooth GATT Introduction

Source: Internet
Author: User
Tags uuid
1. Introduction

GATT (Generic Attribute profile) describes a service framework that uses ATT
The framework defines the process (Procedure) and format of the service (Server) and service properties (characteristic)
Procedure defines characteristic discovery, read, write, notification (notifing), instructions (indicating)
and configure the characteristic broadcast

GATT can be used by application or other profiles
The protocol stack is shown below
---------------        ---------------
| Application | <----> | Application |
---------------        ---------------
|        Attribute | | Attribute |
| Protocol | <----> | Protocol |
---------------        ---------------
| L2cap |    <----> | L2cap |
---------------        ---------------
| Controller |  <----> | Controller |
---------------        ---------------

The GATT can be configured as the following two roles (role)
-Client: command, request initiator
-Server: command, request receiver

The role configuration instance is as follows

     _________ 
    / ======= \ 
   / __________\ 
  | ___________ |     Request      /\ 
  | | Computer | |   ---------->   // 
  | | ( Client) | |   <----------  //Sensor (Server) 
  | |_________| |     Response  // 
  \=____________/\/"" "" "" "" "" "" 
  \  
 /:::::::::::   

Computer is a temperature service client, sensor is a temperature service server
Computer to sensor procedure to read the value of sensor

The requirements for the lower levels of GATT are as follows
-Physical Link: Att created with gap Channel establishment Bearer
-GATT role: not dependent on the Coontroller character (Master/slave)
-Security: For Le,security Features (Authorization, authentication, encryption) is optional
For BR/EDR, encryption is mandatory.
-Multi-byte field in TX Order:gatt with least significant octet first (Little Endian) 2 content 2.1 configured broadcast

For Le physical links, during the server broadcast mode
Client via configured broadcast informs the server that it should add characteristic Value to advertising data

Method is the client setting of the specified bit bit
Broadcast frequency is part of the definition of service, characteristic behavior 2.2 GATT profile Hierarchy

GATT Specifies the structure of the data interaction (Structure)
This structure defines some basic elements, such as service, characteristic
These elements exist in the attribute


At the top of the GATT is profile,profile consisting of one or more services (service)
A service is made up of characteristics, or a reference to another service (Reference)
Characteristic contains a value that may contain information about the value 2.2.1 Service

A service is a collection of [data] and associated [behavior that accomplishes a specific function]/[attribute]
In GATT, a service is implemented by the service definition (defintion)
A service definition may contain reference services (Reference service), mandatory characteristic, and optional characteristic

In order to achieve compatibility with older versions, service definitions in the new version can only add new reference services or optional characteristic
Service definitions in the new version prohibit changing behavior from the old service definition

There are two types of server
-Primary Service: Services with basic functionality that can be included with other services and can be discovered through the Primary service discovery process
-Secondary service: Only for services referenced by Primary/other secondary service, high-level protocol

Interpreting a service that is primary or secondary services can be mandated by a high-level protocol 2.2.2 Included service

A included service is a way to refer to existing services.
The specific approach is to add a reference to the included service at the beginning of the services definition,
So the entire included service definition becomes part of the new service definition 2.2.3 characteristic

Characteristic is defined by the characteristic definition,
Contains a description of the characteristic declaration, characteristic attribute, value, value (Optional) 3 Service Interoperability Requirements 3.1 Service Definition

The service definition includes a service Declaration
may contain include definitions and characteristic definitions
Ends before the next service statement or when you arrive at maximum Attribute handle
The service definition renders the include definitions and characteristic definitions in the service definition on the service side based on the attribute handle order is considered part of the service
The order in the service definition is
Service Declaration ~ Include definitions (>=0) ~ Characteristic definitions (>=0)

Service declaration are as follows

Attribute Handle Attribute Type Attribute Value Attribute Permission
0xNNNN 0x2800–uuid for <primary service>
0x2801–uuid for <secondary service>
16-bit Bluetooth UUID
128-bit UUID for Service
Read only,
No Authentication,
No Authorization

The rules are as follows:
-When multiple services are present
Services defined using the 16-bit Bluetooth UUID service should be grouped (as ordered)
Similarly, service-defined services that use the 128-bit uuid are also grouped
-a device or a high-level protocol may have multiple service definitions, while multiple service definitions contain the same services UUID
-All attributes on the server should contain a service declaration or a service definition exists
-Service definition on the server may be unordered; The client should not assume that the service definition of the server must be an orderly 3.2 Include definition

An include definition contains only one include Declaration

Include declaration as follows

Attribute Handle Attribute Type Attribute Value Attribute Permission
0xNNNN 0x2802–uuid
For<include>
Included Service
Attribute Handle
End Group
Handle
Service UUID Read only,
No Authentication,
No Authorization

Where the UUID is only present when the 16-bit is a Bluetooth uuid

If the include definition (a) of a service is a reference to another server's include definition (B)
Then the include definition (B) should not refer to the Include definition (A), otherwise it is a circular reference (Circular Reference)

When a client detects a circular reference or detects nested include declarations to a greater level than it expects
Client should terminate this communication (ATT Bearer) 3.3 characteristic Definition

Characteristic definition contains the following content
-Characteristic Declaration:first
-Characteristic Value Declaration:second
-Characteristic descriptor Declarations (Optional): Last (with multiple order not critical)

Characteristic definitions in attribute handle order on the server

Each of the above Declaration is contained in a separate attribute 3.3.1 characteristic Declaration

Characteristic declaration as follows

Attribute Handle Attribute Type Attribute Value Attribute Permission
0xNNNN 0x2803
–uuid for
Characteristic
Characteristic
Properties
Characteristic
Value
Attribute Handle
Characteristic
Uuid
Read only,
No Authentication,
No Authorization

Where Attribute value is read-only
The Attribute value field is as follows

Attribute Value Size Description
Characteristic Properties 1 octets Bit field of characteristic properties
Characteristic
Value Handle
2 octets Handle of the Attribute containing the value of this characteristic
Characteristic UUID 2/16 octets 16-bit Bluetooth uuid or 128-bit uuid for characteristic Value

A service may contain characteristic with the same characteristic UUID definitions

In a service definition, some mandatory characteristics should precede the include declarations and other optional characteristics
And the client should not think that characteristic is orderly.
Also, 16-bit bluetooth UUIDs and 128-bit bluetooth UUIDs should be grouped separately

Characteristic properties determines the following as a bit bit
-How to use characteristic value
-Characteristic descriptors access mode

The details of the characteristic Properties bit field are as follows
Notice: Multiple bits can be set simultaneously

Properties Value Description
Broadcast 0x01 If set, permits broadcasts of the characteristic Value
Using characteristic Configuration descriptor
Read 0x02 If set, permits reads of the characteristic
Value using procedures defined in Section 4.8
Write without
Response
0x04 If set, permit writes of the characteristic Value
Without response using procedures
defined in section 4.9.1
Write 0x08 If set, permits writes of the characteristic Value
With response using procedures
defined in sections 4.9.3 or section 4.9.4
Notify 0x10 If set, permits notifications of a characteristic Value
Without acknowledgement using the procedure
Defined in section 4.10
Indicate 0x20 If set, permits indications of a characteristic Value
With acknowledgement using the procedure
Defined in section 4.11
Authenticated
Signed writes
0x40 If set, permits signed writes to the characteristic Value
Using the procedure defined in section 4.9.2
Extended
Properties
0x80 If set, additional characteristic properties are
Defined in the characteristic Extended Properties descriptor
defined in section 3.3.3.1
3.3.2 characteristic Value Declaration

Characteristic Value declaration is as follows

Attribute Handle Attribute Type Attribute Value Attribute Permissions
0xNNNN 0xuuuu–16-bit Bluetooth UUID
Or
128-bit uuid for characteristic uuid
Characteristic Value Higher layer Profile
Or
Implementation specific
3.3.3 Characteristic descriptor Declarations

Characteristic descriptor declarations contains characteristic value related information

GATT defines a series of standard characteristic descriptors for use in high-level protocols
High-level protocols can also define protocol-related characteristic descriptors

Characteristic descriptors on the service side is disorderly, the client should not be taken for granted
Characteristic descriptors Declarations permissions by a high-level protocol definition or protocol-related
The client should not be taken for granted to be readable

Characteristic descriptor declarations includes the following (see Specification for details)

-Characteristic Extended Properties
-Characteristic User Description
-Client characteristic Configuration
-Server characteristic Configuration
-Characteristic Presentation Format
-Characteristic Aggregate Format 3.4 Summary of GATT profile Attribute Types

Attribute Type Uuid Description
<primary service> 0x2800 Primary Service Declaration
<secondary service> 0x2801 Secondary Service Declaration
<Include> 0x2802 Include Declaration
<Characteristic> 0x2803 Characteristic Declaration
<characteristic Extended properties> 0x2900 Characteristic Extended Properties
<characteristic User description> 0x2901 Characteristic User Description descriptor
<client characteristic configuration> 0x2902 Client characteristic Configuration descriptor
<server characteristic configuration> 0x2903 Server characteristic Configuration descriptor
<characteristic format> 0x2904 Characteristic Format descriptor
<characteristic Aggregate format> 0x2905 Characteristic Aggregate Format descriptor
4. GATT Feature Requirements 4.1 Overview

11 items are defined in the GATT feature
1. Server Configuration
2. Primary Service Discovery
3. Relationship Discovery
4. Characteristic Discovery
5. Characteristic descriptor Discovery
6. Reading a characteristic Value
7. Writing a characteristic Value
8. Notification of a characteristic Value
9. Indication of a characteristic Value
Ten. Reading a characteristic descriptor
Writing a characteristic descriptor

Each Feature has a corresponding procedure and sub-procedure that describes how to use the ATT to implement the respective functions 4.2 Feature Support and Procedure Mapping

The detailed correspondence list is as follows table

No

Feature

Sub-procedure

Ref

Client
Support

Server
Support

1

Server Configuration

Exchange MTU

4.3.1

O

O

2

Primary Service

Discovery

Discover all Primary Services

4.4.1

O

M

Discover Primary Services by
Service UUID

4.4.2

O

M

3

Relationship Discovery

Find Included Services

4.5.1

O

M

4

Characteristic
Discovery

Discover all characteristic of a Service

4.6.1

O

M

Discover characteristic by UUID

4.6.2

O

M

5

Characteristic
Descriptor Discovery

Discover all characteristic descriptors

4.7.1

O

M

6

Characteristic

Value Read

Read characteristic Value

4.8.1

O

M

Read Using characteristic UUID

4.8.1

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.