Bluetooth Profile 蓝牙协议栈总结

GAP-Generic Access Profile

控制设备广播和连接

GAP profile 的目的是描述:

  • Profile roles
  • Discoverability modes and procedures
  • Connection modes and procedures
  • Security modes and procedures
    在这里插入图片描述在这里插入图片描述
    设备连接过程
    在这里插入图片描述
    LE中GAP有4种角色:
  • Broadcaster
  • Observer
  • Peripheral - 数据源,如手环;连接后是slave模式
  • Central - 中心设备,如手机,PC;连接后是master模式

在这里插入图片描述

ATT-Attribute Profile

ATT协议定义了一些角色,每个角色都有它特定的功能。这些角色都是基于Client-Server架构的。

  • 服务器(Server):作为一个数据库,存储可被客户端读写的数据
  • 客户端(Client):请求服务器上的数据

但有一个误区:Central设备将作为ATT的客户端,Peripheral设备将作为ATT的服务端。但实际上Central和Peripheral都既可以做服务端,也可以做客户端。比如,一个可以记录步数、心率等信息的蓝牙智能手环。当手环想向手机传输这些信息的时候,它作为服务端,而手机作为客户端;手环上可以显示当前的时间,这是由手机传过去的,此时手机作为服务端,而手环作为客户端
ATT协议负责为服务端设备提供客户端能读写的指定格式化的数据,以及客户端访问、写入和读取数据的机制。
1. Attribute
ATT协议定义了一个叫attribute的数据结构,该数据结构由下列四个字段组成:
在这里插入图片描述

  • Attribute Handle :用于给客户端查找一个服务端attribute的uint16_t类型的唯一标识符,也就是给attribute一个“地址”
  • Attribute Type (UUID) :全局唯一的2或16字节的UUID标识符,定义储存于Attribute Value中的数值的具体类型和含义
  • Attribute Value:属性值
  • Attribute Permissions:它表示访问Attribute Value的权限,或者说设置一个属性的安全等级

在服务端,数据以如下Attribute表格形式存储:
在这里插入图片描述
2. Attribute访问方式
ATT协议还定义了读写属性的方式。具体的方式取决于发起属性访问过程的是客户端还是服务端。
1 客户端发起属性访问,有两种操作——WriteRead

  • 客户端使用Read从服务器读取属性的值,服务器响应属性的值
  • 客户端使用Write将一个属性的值写入服务器,服务器响应写操作是否成功

2 服务端发起属性访问,有两种操作——NotificationIndication

  • Notification:当Attribute发生改变时,服务端使用该种方式向客户端发送更新后的属性值,客户端收到后不响应此操作
  • Indication:与Notification类似,但是客户端必须发送是否正确收到该Attribute的响应、
    在这里插入图片描述

3 Attribute访问权限
访问权限决定客户端是否可以读、写或读写其中某个属性值,可选权限如下:

  • None:没有读写权限
  • Readable:可读
  • Writable:可写
  • Readable and writable:可读写

注意:Attribute handle和Attribute type是公共信息,而Attribute Value和Attribute Permissions是私有信息。为了让客户端可以访问这两个私有信息,服务端需要进行如下操作:

  • 读或写的身份验证
  • 读或写的授权
  • 读或写的加密和配对

总结

  • ATT协议负责管理设备之间的数据存储。它为服务端提供了一种客户端可以进行读写的Attribute数据结构,并为客户端提供了访问、写入和读取数据的机制(访问方法和权限)。
  • GATT层定义了一个层次化的数据结构,它有助于理解存储在服务端中数据(GATT Profile)之间的关系。

原文链接:https://blog.csdn.net/tilblackout/article/details/127944589

GATT-Generic Attribute Profile

GATT层负责定义分层数据结构,该结构演示了ATT服务器中存储的数据之间的关系或连接。(类似文件夹和文件)
GATT协议层定义了一个框架,在该框架中,服务端数据库上的Attribute可以被组织起来而有一定的层次关系。GATT层定义了一个4层树形框架,其中根节点为Profile(配置),它有不同的Services(服务),不同的服务有不同的Characteristics(特征),不同的特征通过一个具体的Value(值)或者Descriptor(描述符)来定义,如下图所示。
在这里插入图片描述
在这里插入图片描述

Service结构
在这里插入图片描述
在这里插入图片描述

Characteristic结构

Characteristic有一个特殊的descriptor——Client Configuration Characteristic descriptor(CCCD)
一般而言,都是cilent来访问server的characteristic,我们把这种操作称作为读或写,另外,server可以直接把自己的charactertis的值告诉client,我们称作为notify或者indicate,跟read操作相比,只有需要传输数据的时候或者说数据有效时,server才开始notify或者indicate数据到client,因此这种操作方式可以大大节省server的功耗,有时候client不想监听characteristic notify或者indicate过来的数据,那么就可以使用CCCD来关闭characteristic 的notify或者indicate功能,如果client又需要监听characteristic 的notify或者indicate,俺么它可以重新使能CCCD来打开相关操作,总结一下,当characteristic 具有notify或者indicate操作功能时,那么必须添加CCCD,以方便cilent来使能或者禁止notify功能

GATT通过ATT传输数据
在这里插入图片描述

总结

  • ATT协议负责管理设备之间的数据存储。它为服务端提供了一种客户端可以进行读写的Attribute数据结构,并为客户端提供了访问、写入和读取数据的机制(访问方法和权限)。
  • GATT层定义了一个层次化的数据结构,它有助于理解存储在服务端中数据(GATT Profile)之间的关系。

SDP-Service Discovery Protocol

SDP的全称是Service Discovery Protocol,中文是服务发现协议。SDP(服务发现协议)是蓝牙协议体系中的核心协议,是蓝牙系统重要组成部分,是所有用户模式的基础。在蓝牙系统中.客户端只有通过服务发现协议才能获得设备信息、服务信息及服务特征,才能在此基础上建立相互间的连接。通过这个协议,应用程序可以发现哪些服务可用以及服务的特性是什么。
SDP服务器-客户端模型:
在这里插入图片描述

客户端通过发送SDP请求给服务器查询服务以及服务的属性。SERVICE RECORD包含了SDP Server的所有信息,它由一系列的service attributes组成,如图:
在这里插入图片描述

service attribute描述了服务的特性。它由属性ID和属性值组成。属性ID 是一个16位无符号整数,以便区别于服务记录中的其他服务属性。服务类属性由属性ID和属性值组成。属性值是一千长度可变的字段。它的含义由属性记录中枢应的属性ID和服务类确定。

SPP-Serial Port Profile

在这里插入图片描述
在这里插入图片描述

Device A是发起连接的主动方,所以Device A要至少支持Establish link and set up virtual serial connection.,Device B是被连接的乙方,所以要至少支持Accept link and establish virtual serial connection和Register Service record for application in local SDP database.以便Device A查询服务并且连接,但是此协议漏掉最主要的两个功能,发送数据,接收数据,或者SIG是觉得rfcomm做到了这个功能,所以不写在SPP协议中吧
1 Establish link and set up virtual serial connection.
This procedure refers to performing the steps necessary to establish a connection to an emulated serial port (or equivalent) in a remote device. The steps in this procedure are:

  1. Submit a query using SDP to find out the RFCOMM Server channel number of the desired application in the remote device. This might include a browsing capability to let the user select among available ports (or services) in the peer device. Alternatively, if it is known exactly which service to contact, it is sufficient look up the necessary parameters using the Service Class ID associated with the desired service.
  2. Optionally, require authentication of the remote device to be performed. Also optionally, require encryption to be turned on.
  3. Request a new L2CAP channel to the remote RFCOMM entity.
  4. Initiate an RFCOMM session on the L2CAP channel.
  5. Start a new data link connection on the RFCOMM session, using the aforementioned server channel number.After step 5, the virtual serial cable connection is ready to be used for communication between applications on both sides.

2 Accept link and establish virtual serial connection.
This procedure refers to taking part in the following steps:

  1. If requested by the remote device, take part in authentication procedure and, upon further request, turn on encryption.
  2. Accept a new channel establishment indication from L2CAP.
  3. Accept an RFCOMM session establishment on that channel.
  4. Accept a new data link connection on the RFCOMM session. This may trigger a local request to authenticate the remote device and turn on encryption, if the user has required that for the emulated serial port being connected to (and authentication/encryption procedures have not already been carried out).

3 Register Service record for application in local SDP database.
This procedure refers to registration of a service record for an emulated serial port (or equivalent) in the SDP database. This implies the existence of a Service Database, and the ability to respond to SDP queries.

需要注意的是,SPP只有安卓手机支持,并且部分安卓手机必须有SPP APP才可以连接,iphone手机不能直接SPP,但是又一个替代协议IAP,此协议需要买MFI chip才能用

  • 17
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值