BLE协议简述

本文简要叙述BLE协议栈构成, 并在应用层上简介zephyr和BLE协议的对应。

概览 链接到标题

BLE协议分为BLE Application和BLE Core两部分, BLE Core又分为Host和Controller两部分,如下图 BLE Controller负责定义物理规范,并基于硬件抽象逻辑链路层. Host基于逻辑链路进行封装,对应用更为友好. Application:应用层

Controller 链接到标题

Physical Layer 链接到标题

物理层描述硬件特性包含射频(RF),调制方式,传输码率.

RF 链接到标题

  • 40个物理通道
  • 每个通道带宽2M
  • ISM频段2400M~2483.5M

Modulation & Data Rate 链接到标题

  • GFSK调制
  • 1Mbps/2Mbps传输码率

链路层对物理层进行逻辑划分和控制

  • 将40个物理划分为3个广播(advertising)通道和37个数据(Data)通道 channel
  • 采用跳频(Hopping)通讯,进行通道管理 hopping ahopping
  • 规定数据包格式 packet
  • 负责广播,发现,连接的创建和维护
  • 提供校验重传机制,确保数据可靠

HCI 链接到标题

Host Controller interface,Host和Controller之前的接口,当Host和Controller位于两个不同的物理实体时的通讯协议,HCI可以是uart/USB/spi. 例如我有一颗uart的Controller的BLE芯片,那么可以在PC上实现host,并通过uart访问控制Controller。

Host 链接到标题

L2CAP 链接到标题

Logical Link Control and Adaptation Protocol, 为了让上层更方便的使用Link layer. Link layer有组多限制,例如包的大小等等,通过L2CAP来适配,这里不做展开.

SM 链接到标题

Security Manager, 安全管理(配对,认证,加密)

GAP 链接到标题

Generic Access Profile,通用访问配置文件,定义蓝牙设备的角色(Role:Peripheral & Central),用于BLE device的连接

  • Central: 连接发起者(Client 请求数据)
  • Peripheral: 被连接者(Server 响应请求,提供数据)

ATT 链接到标题

Attribute Protocol, 用于“发现,读,写”设备,所有的BLE Service都使用ATT做为应用层协议。 ATT

  • Attribute Handle: 访问属性的handle
  • Attribute Type: UUID(官方16bit, 自定义128bit)
  • Attribute Value: 属性值
  • Attribute Permissions: 属性的读写等权限

GATT 链接到标题

Generic Attribute Profile 通用属性配置文件,用于BLE device连接后的数据传输。GATT在ATT之上规定了在service中使用ATT的方法。所有LE profile都必须基于GATT协议。 GATT使用ATT定义的Attribute来表示Descriptor/Characteristic/Service,,由Descriptor组成Characteristics,由多个Characteristics组成Service,多个Service组成Profile。 gatt

Application 链接到标题

Gatt-base profile & serivce 链接到标题

BLE划分上APP内需要用基于GATT实现profiles & service,相关规范

Application 链接到标题

基于GAP & GATT profiles的应用程序

Zephyr BLE应用相关API 链接到标题

GAP 链接到标题

相关API定义在include/bluetooth.h

GATT 链接到标题

相关API定义在include/bluetooth/gatt.h

BLE连接管理 链接到标题

相关API定义在include/bluetooth/conn.h

参考 链接到标题

https://www.bluetooth.com/zh-cn/specifications/bluetooth-core-specification https://www.bluetooth.com/zh-cn/specifications/gatt http://microchipdeveloper.com/wireless:ble-introduction http://lausai360.blogspot.com/2017/02/ble-att-gatt-protocol.html https://www.jianshu.com/p/62eb2f5407c9