日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BLE中GATT介绍

發布時間:2024/3/24 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BLE中GATT介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文轉載自博客園

1 簡介

GATT(Generic Attribute Profile),描述了一種使用ATT的服務框架
該框架定義了服務(Server)和服務屬性(characteristic)的過程(Procedure)及格式
Procedure定義了characteristic的發現、讀、寫、通知(Notifing)、指示(Indicating)
及配置characteristic的廣播

GATT可以被Application或其他Profile使用
其協議棧如下圖
——————????????????——————
| Application | <—-> | Application |
——————????????????——————
|? ?Attribute??|???????????? |?? Attribute?? |
|? ?Protocol?? | <—-> ?|???Protocol???|
——————????????????——————
|??? L2CAP???? | <—-> ?|??? ?L2CAP?????|
——————????????????——————
|? Controller | <—-> ?|?? Controller |
——————????????????——————

?

GATT可以配置為如下兩種角色(Role)
- Client : 命令、請求發起方
- Server : 命令、請求接收方

?

?

角色配置實例如下

?

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

?

?

Computer是一個溫度服務客戶端, Sensor是溫度服務服務器
Computer向Sensor發起Procedure來讀Sensor的值

?

GATT對下層的需求如下
- Physical Link : 使用GAP Channel Establishment建立的ATT Bearer
- GATT Role???? : 不依賴于Coontroller角色(Master/Slave)
- Security????? : 對于LE,Security Features(Authorization、Authentication、Encryption)是可選的
????????????????? 對于BR/EDR, Encryption是強制的
- TX order????? : GATT中的多字節字段,采用Least Significant octet先發送(Little Endian)

?

2 內容

?

2.1 Configured Broadcast

?

對于LE物理鏈路,在Server廣播模式過程中
Client通過Configured Broadcast告知Server應該在advertising data加入Characteristic Value

?

方法是Client設置指定bit位
廣播頻率則是Service、Characteristic行為定義的一部分

?

?

2.2 GATT Profile Hierarchy

?

GATT指定了數據交互的結構(Structure)
這個結構體定義了一些基本元素,如Service、Characteristic
這些元素存在于Attribute中

GATT中最上層是Profile,Profile由一個或多個服務(Service)組成
服務是由Characteristics組成,或是其他服務的引用(Reference)
Characteristic包含一個值(Value),可能包含該Value的相關信息

2.2.1 Service

Service是[數據]和與之關聯的[完成某個特定功能的行為]/[特性]的集合
在GATT中,一個服務由服務定義(Service Defintion)來實現
一個服務定義可能包含引用服務(Reference Service)、強制Characteristic和可選Characteristic

為了實現舊版本的兼容,新版本中服務定義只能增加新的引用服務或可選Characteristic
新版本中的服務定義禁止從舊的服務定義中改變行為

Server有兩類
- Primary Service?? : 擁有基本功能的服務,可被其他服務包含,可以通過Primary Service Discovery過程來發現
- Secondary Service : 僅用來被Primary/Other Secondary Service、高層協議引用的服務

判讀一個服務是Primary or Secondary Service可通過高層協議強制規定

2.2.2 Included Service

一個Included Service是一種引用已存在服務的方法,
具體辦法為在服務定義的開始加上Included Service的引用,
這樣整個Included Service定義成為新服務定義的一部分

2.2.3 Characteristic

Characteristic由Characteristic Definition定義,
包含一個Characteristic聲明、Characteristic屬性、值、值的描述(Optional)

?

3 Service Interoperability Requirements

3.1 Service Definition

服務定義(Service Definition)包含一個服務申明(Service Declaration)
??? 可能包含Include Definitions和Characteristic Definitions
在下一個服務申明前或到達Maximum Attribute Handle時結束
服務定義在服務端上基于Attribute Handle順序呈現

服務定義中的Include Definitions和Characteristic Definitions被認為是服務的一部分
服務定義中的順序為
Service Declaration ~ Include Definitions(>=0) ~ Characteristic Definitions(>=0)

Service Declaration如下

Attribute HandleAttribute TypeAttribute ValueAttribute Permission
0xNNNN0x2800 – UUID for <Primary Service>
0x2801 – UUID for <Secondary Service>
16-bit Bluetooth UUID
128-bit UUID for Service
Read Only,
No Authentication,
No Authorization

?

?

規則如下:
- 當多個服務存在時
????? 使用16-bit Bluetooth UUID服務定義的服務應該分組(如按順序排列)
????? 同理,使用128-bit UUID的服務定義的服務也分組
- 一個設備或高層協議可能有多個服務定義,同時多個服務定義含有相同的Service UUID
- 服務端的所有Attributes應該包含一個服務聲明或存在一個服務定義
- 服務端的服務定義可能無序;Client不應該認為服務端的服務定義一定是有序的

?

3.2 Include Definition

?

一個Include Definition只包含一個Include Declaration

Include Declaration如下

Attribute HandleAttribute TypeAttribute ValueAttribute Permission
0xNNNN0x2802 – UUID
for<Include>
Included Service
Attribute Handle
End Group
Handle
Service UUID Read Only,
No Authentication,
No Authorization

其中,僅當UUID是16-bit Bluetooth UUID時才存在

如果一個Service的Include Definition(A)是引用其他Server的Include Definition(B)
那么Include Definition(B)不應該引用Include Definition(A),否則就是循環引用(Circular Reference)

當一個Client檢測到循環引用或detects nested include declarations to a greater level than it expects
Client應當終止本次通信(ATT Bearer)

?

?

3.3 Characteristic Definition

?

Characteristic Definition包含如下內容
- Characteristic Declaration?????????????????????? : First
- Characteristic Value declaration???????????????? : Second
- Characteristic Descriptor Declarations(Optional) : Last(含多個時順序不關緊要)

?

Characteristic Definitions在服務端以Attribute Handle排序

?

以上每個Declaration包含在一個單獨的Attribute中

?

3.3.1 Characteristic Declaration

?

Characteristic Declaration如下

?

Attribute HandleAttribute TypeAttribute ValueAttribute Permission
0xNNNN0x2803
– UUID for
Characteristic
Characteristic
Properties
Characteristic
Value
Attribute Handle
Characteristic
UUID
Read Only,
No Authentication,
No Authorization

?

其中,Attribute Value只讀
Attribute Value字段如下

Attribute ValueSizeDescription
Characteristic Properties 1 octetsBit field of characteristic properties
Characteristic
Value Handle
2 octetsHandle of the Attribute containing the value of this characteristic
Characteristic UUID2/16 octets16-bit Bluetooth UUID or 128-bit UUID for Characteristic Value

一個Service可能含有相同Characteristic UUID的Characteristic Definitions

在一個服務定義中,一些強制的Characteristics應該位于Include Declarations之后、其他可選characteristics之前
而Client不應該認為Characteristic是有序的
同時,16-bit Bluetooth UUIDs和128-bit Bluetooth UUIDs應該分別分組

Characteristic Properties以bit位的方式決定如下內容
- Characteristic Value的使用方式
- Characteristic Descriptors的訪問方式

Characteristic Properties bit field的詳細內容如下
Notice: 多個比特位可以同時設置

?

PropertiesValueDescription
Broadcast0x01If set, permits broadcasts of the Characteristic Value
using Characteristic Configuration Descriptor
Read0x02If set, permits reads of the Characteristic
Value using procedures defined in Section 4.8
Write Without
Response
0x04If set, permit writes of the Characteristic Value
without response using procedures
defined in Section 4.9.1
Write0x08If set, permits writes of the Characteristic Value
with response using procedures
defined in Section 4.9.3 or Section 4.9.4
Notify0x10If set, permits notifications of a Characteristic Value
without acknowledgement using the procedure
defined in Section 4.10
Indicate0x20If set, permits indications of a Characteristic Value
with acknowledgement using the procedure
defined in Section 4.11
Authenticated
Signed Writes
0x40If set, permits signed writes to the Characteristic Value
using the procedure defined in Section 4.9.2
Extended
Properties
0x80If 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如下

?

Attribute HandleAttribute TypeAttribute ValueAttribute Permissions
0xNNNN0xuuuu – 16-bit Bluetooth UUID
or
128-bit UUID for Characteristic UUID
Characteristic ValueHigher layer profile
or
implementation specific

?

3.3.3 Characteristic Descriptor Declarations

?

?

Characteristic Descriptor Declarations包含了Characteristic Value相關信息

GATT定義了一系列的標準Characteristic Descriptors供高層協議使用
高層協議也可以定義協議相關的Characteristic Descriptors

Characteristic Descriptors在服務端上是無序的,Client不應該理所當然
Characteristic Descriptors Declarations Permissions由高層協議定義或協議相關的
Client不應該理所當然地認為是可讀的

Characteristic Descriptor Declarations包括如下內容(詳細見規范)

- 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 TypeUUIDDescription
<Primary Service>0x2800Primary Service Declaration
<Secondary Service>0x2801Secondary Service Declaration
<Include>0x2802Include Declaration
<Characteristic>0x2803Characteristic Declaration
<Characteristic Extended Properties>0x2900Characteristic Extended Properties
<Characteristic User Description>0x2901Characteristic User Description Descriptor
<Client Characteristic Configuration>0x2902Client Characteristic Configuration Descriptor
<Server Characteristic Configuration>0x2903Server Characteristic Configuration Descriptor
<Characteristic Format>0x2904Characteristic Format Descriptor
<Characteristic Aggregate Format>0x2905Characteristic Aggregate Format Descriptor

?

4. GATT Feature Requirements

?

?

4.1 Overview

GATT中定義了11項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
10. Reading a Characteristic Descriptor
11. Writing a Characteristic Descriptor

?

每個Feature都有對應的過程和子過程,這些過程描述了如何使用ATT來實現各自的功能

?

?

4.2 Feature Support and Procedure Mapping

詳細的對應列表如下表

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

O

M

Read Long Characteristic Values

4.8.2

O

O

Read Multiple Characteristic Values

4.8.3

O

O

7

Characteristic

Value Write

Write Without Response

4.9.1

O

C.1

Signed Write Without Response

4.9.2

O

O

Write Characteristic Value

4.9.3

O

C.2

Write Long Characteristic Values

4.9.4

O

O

Characteristic Value Reliable Writes

4.9.5

O

O

8

Characteristic

Value Notification

Notifications

4.10.1

O

O

9

Characteristic

Value Indication

Indications

4.11.1

M

C.3

10

Characteristic
Descriptor Value Read

Read Characteristic Descriptors

4.12.1

O

O

Read Long Characteristic Descriptors

4.12.2

O

O

11

Characteristic
Descriptor Value Write

Write Characteristic Descriptors

4.12.3

O

O

Write Long Characteristic Descriptors

4.12.4

O

O

C1: Write Without Response is mandatory if Signed Write Without Response is supported

otherwise optional

C2: Write Characteristic Value is mandatory if Write Long Characteristic Values is supported

otherwise optional

C3: If Service Change Characteristic is present, this feature is mandatory, otherwise optional.

?

4.3 Server Configuration

該過程可被Client用來配置Attribute Protocol的MTU大小

4.3.1 Exchange MTU

Client使用該子過程來設置適配雙方均支持的最大ATT_MTU

在BR/EDR物理鏈路中不應該使用該過程,而應該使用L2CAP Channel Configuration Procedures

該過程對應于ATT的MTU Exchange Request/Response
見<Bluetooth ATT介紹 - 4.2 MTU Exchange>

4.4 Primary Service Discovery

Client使用該過程來發現服務端的Primary Services
一旦發現服務存在,可通過其他過程來訪問Primary Services的附加信息(關聯主服務和次服務)
可使用的其他過程包括Characteristic Discovery和Relationship Discovery

該過程包括兩個子過程:
- Discover All Primary Services
- Discover Primary Services by Service UUID

在BR/EDR物理鏈路上則使用SDP service discovery來發現服務

4.4.1 Discover All Primary Services

Client使用該子過程來發現服務端的所有Primary Services

該子過程使用ATT的Read By Group Type Request,同時設置如下參數
- Starting Handle : 0x0001
- Ending Handle?? : 0xFFFF
- Attribute Type? : UUID for <Primary Service>

可能的回應有
- Read By Group Type Response
- Error Response

Read By Group Type Response返回三元組列表
三元組包括
- Attribute Handle : 服務聲明的Handle
- End Group Handle : 服務定義中最后一個Attribute的Handle
- Attribute Value? : 服務端支持的服務的Service UUID

當收到Error Response<Error Code: Attribute Not Found>時
則表明該過程已經完成

當Client找到自己所需要的服務時,可以終止該過程

Note: 3.1中已指出Service Declaration是可讀,并且不需要認證或授權
???????? 因此權限相關的錯誤不會發生

下圖是一個實例圖

?

4.4.2 Discover Primary Service by Service UUID

當Client只知道Service UUID時,可以使用該子過程來發現對應的主服務

?

該子過程使用ATT的Find By Type Value Request,同時設置參數如下
- Starting Handle : 0x0001
- Ending Handle?? : 0xFFFF
- Attribute Value : 16-bit Bluetooth UUID or 128-bit UUID
- Attribute Type? : UUID for <Primary Service>

可能的回應有
- Find By Type Value Response
- Error Response

Find By Type Value Response返回Attribute Handle ranges列表
Attribute Handle range即服務定義的Starting Handle和Ending Handle
如果Attribute Handle range中的End Found Handle不是0xFFFF
那么Client將會再請求一次Req
同時將Starting Handle設置為收到的最后一個Attribute Handle+1

終止規則和權限問題同Discover All Primary Services

下圖是一個實例圖

4.5 Relationship Discovery

Client使用該過程來發現和其他服務的服務關系

4.5.1 Find Include Services

Client使用該子過程來發現一個服務定義包含的服務申明

該子過程使用ATT的Read By Type Request,同時設置參數如下
- Starting Handle : 所要查找服務的Starting Handle
- Ending Handle?? : 所要查找服務的Ending Handle
- Attribute Type? : UUID for <Include>

可能的回應有
- Find By Type Response
- Error Response

Find By Type Response返回[Attribute Handle, Attribute Value]集合對
Attribute Value由所包含服務申明的Attribute Handle和End Group Handle組成
當UUID為16-bit Bluetooth UUID時,那么它也將包含在Rsp中

該Req應該被再次請求,同時設置Starting Handle為為收到的最后一個Attribute Handle+1

當Rsp中包含的服務申明中Attribute Handle等于Req的Ending Handle時,
該子過程被認為完成(當然Attribute Not Found-Error Rsp也是)

當Include Service使用128-bit UUID時
使用Read Request來獲取Include Service UUID
其中Attribute Handle參數設置為Include Service的Attribute Handle

權限規則同上面

下圖是一個實例圖

?

總結

以上是生活随笔為你收集整理的BLE中GATT介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 成人一区三区 | 色女人av| 精品国产午夜福利在线观看 | 一级久久久 | 欧美日日操 | 男女吻胸做爰摸下身 | 在线视频激情小说 | 国产剧情一区在线 | 两性动态视频 | 亚洲欧美午夜 | 国内成人精品视频 | 日本涩涩网站 | 午夜亚洲福利在线老司机 | 日本不卡视频一区二区三区 | 伊人狠狠干 | 亚洲精品一区久久久久久 | 国产一区二区四区 | 尹人在线视频 | 奇米精品一区二区三区在线观看一 | 91桃色视频在线观看 | 黄色av影院 | 国产精品视频久久久久久 | 天堂av资源 | 一区二区三区中文视频 | 精品国模一区二区三区 | 用舌头去添高潮无码视频 | 午夜成人免费视频 | 国产美女无遮挡永久免费 | 男人天堂资源网 | 91麻豆精品久久久久蜜臀 | 天天色综合久久 | av黄色小说| 狠狠干狠狠艹 | 成人在线直播 | 黄色一级片在线免费观看 | 欧美国产精品一二三 | 日本中文字幕免费 | 国产精品无码AV无码国产 | 男人添女人下部高潮全视频 | 日韩精品一区二区三区免费视频 | 久久久国产精品x99av | 久久久www成人免费毛片 | 国产女人毛片 | 欧美黑人狂野猛交老妇 | 国产福利专区 | 国产青青| 美女被叉叉的影院 | 米奇av| 日韩精品成人在线观看 | 美女隐私无遮挡 | 青青草免费观看视频 | 久久久啊啊啊 | 日日拍拍 | 五月婷综合 | 91毛片网站| 国产99久久久欧美黑人 | 香蕉小视频 | 天堂√| www.天天操| 性一交一乱一伧老太 | 18被视频免费观看视频 | 在线观看xxxx| 男女爽爽爽 | 嫩草影院在线免费观看 | 国产视频1区2区3区 国产欧美一区二区精品性色99 | 久久夜色精品国产欧美乱 | www.av欧美 | 欧美成人自拍 | 男女激情大尺度做爰视频 | 尤物影院在线观看 | 精品孕妇一区二区三区 | xxx视频网站 | 日韩一区二区三区中文字幕 | 亚洲精品鲁一鲁一区二区三区 | av中文字幕网址 | 色久av | 白嫩白嫩国产精品 | 国产精品黄色网 | 久久激情网 | 久久桃花网| 国产女教师一区二区三区 | 精品久久一二三区 | 美女视频91 | 手机看片日本 | 97精品人人妻人人 | 日本一区二区在线不卡 | 欧美日韩123 | 成人爱爱网站 | 中文字幕 国产精品 | av中文在线观看 | 6080久久| 免费国产羞羞网站视频 | 精品国产一区二区三区日日嗨 | 免费亚洲一区二区 | 一区二区三区免费看 | 亚洲国产一区二区a毛片 | 国产系列精品av | 99国产精品白浆在线观看免费 | 亚洲性夜 |