当前位置:网站首页>[Bluetooth Bluetooth development] VIII. Transmission layer of ble protocol
[Bluetooth Bluetooth development] VIII. Transmission layer of ble protocol
2022-07-28 21:36:00 【Swastika twelve painting Swastika】


List of articles
8.1 Preface

Link Layer The transport layer goes up , It's the transport layer . Transport layer , be located Host and Controller Between layers , Provide the ability to transmit data without knowing the detailed data content . It is mainly transmitted through hardware media ( Such as :UART、USB、SDIO etc. ), transmission Bluetooth HCI The data of .
Here is UART Block diagram of the transport layer :

Look at the picture above , We probably have a general understanding of the transport layer , Let's analyze it in detail .
HCI Detailed introduction , having evidence or referent sources
Core5.0 P670

8.2 HCI(Host Controller Interface) Introduce

Upper figure , Shows the data transmission path between the two devices .Host adopt HCI Driver Driver and Controller On hardware HCI Firmware Exchange data and commands , The transport layer provides such capabilities .
The main role of the transport layer :
- The Bluetooth protocol stack sends the connected to the chip
command - Bluetooth chip reports to Bluetooth protocol stack
command status with create connection opcode - Bluetooth chip reports Bluetooth protocol stack
connect complete
HCI Provides a unified interface for accessing , control Controller, The transport layer is transparent , Independent of the underlying transmission technology , And no relationship Host Transferred to the Controller What is the data of .
stay HOST And Controller Between , With Command And Event Command mode for transmission .Host send out Command Information to Controller,Controller take Command Status and Params With Event Returned to Host, Finally back to Command Complete Event Indicates that the connection is complete .
More intuitive , as follows :

HCI There are four types of package formats , Namely :

- HCI Command Packet: The command sent to the chip by the Bluetooth protocol stack , namely
Host->Controller - HCI Event Packet: Events reported by Bluetooth chip to Bluetooth protocol stack , namely
Controller->Host - HCI ACL Data Packet: Common data of two-way interaction between Bluetooth protocol stack and Bluetooth chip .
- HCI Synchronous Data Packet: Common data of two-way interaction between Bluetooth protocol stack and Bluetooth chip .
Detailed see
Core5.0.pdf P670
stay Host and Controller Between ,HCI The command and event types of are as follows :
Detailed see
Core5.0.pdf P647

The interactive data format is :

8.3 HCI Packet format
HCI Provides a unified command format to access Controller, Different commands also take different time . The transport layer commands Command And events Event To communicate , Now let's mainly look at the format of communication packets .
8.3.1 Handles
Handle: Identification of the channel of the logical link , There are three categories :Connection_Handles, Logical Link Handles, and Physical Link Handles
8.3.1.1 Primary Controller Handles
Connection_Handles: By Primary Controller Handles Distribute , Identify the logical channel between the host and the master controller , When a new logical link is established ,Connection_Handles Will be assigned .
The Handle It is mainly used in :Connection Complete, Synchronous Connection Complete, LE Connection Complete, or LEEnhanced Connection Complete Of Event Incident .
8.3.1.1.1 Broadcast Connection_Handles
Host At the first power on or restart , First send HCI Data packets , Assign a Connection_Handle. thereafter , Use this Handle Go broadcast .
8.3.1.2 AMP Controller Handles
AMP Controllers There are two kinds of :Logical Link Handles, and Physical Link Handles.
about Host And AMP Controller Between Data,Command and Event operation , If Physical Link Handles To be designated , Then use the Handle, If not specified , When specified Connection_Handle Where to use Logical Link Handles
It's not right here AMP Make a detailed description .
8.3.2 HCI Command Packet
HCI Command Packet be used for Host Send a command to Controller controller .
The package format is as follows :

- OpCode Field
OpCode: Occupy two bytes , Used for command identification , Divided into two domains :OCF:OpCode Group Field and OGF OpCode Command Field.
OGF: Occupy high 6bitOCF: Occupy low 10bit, among0X3FCommissioning order for the manufacturer .

- Paramter_Total_Length Field
Paramter_Total_Length: The length of all parameters in the package .

- Paramter Field

8.3.3 HCI Event Packet
Every Command After the command is issued , They always bring one Event Return to the status after the command is executed .
The package format is as follows :

- Event_Code Field
Event_Code: Identify different event types .

- Parameter_Total_Length Field
Parameter_Total_Length: Parameter total length

- Event_Parameter Field
Event_ParameteN: Related parameters

8.3.4 HCI ACL Data Packets
HCI ACL Data Packets Specifies the format of the data packet , be used for Host And Controller Data exchange between .
There are two types of packets :
- Automatically-Flushable: Automatically refresh
Automatically refresh the package , The time of its automatic refresh depends on the set time .
- Non-Automatically-Flushable: Non automatic refresh
Non automatic refresh , The packet will not be refreshed automatically .
The package format is as follows :

- Handle Field
Handle: As mentioned above , There are several types of this field :
Connection_Handle: Used to send packets or segments on the main controllerLogical_Link_Handle: be used for AMP The controller sends packetsPhysical Link Handles: be used for AMP The controller sends packetsFlag Field
Flag Include :PB Flag and BC Flag, namely Packet_Boundary_Flag And Broadcast_Flag, The values are as follows :


8.3.5 HCI Synchronous Data Packets
The packet , Used in Host and Controller Exchange synchronous data between .
The package format is as follows :

- Packet_Status_Flag Field
This field is associated with Erroneous_Data_Reporting Parameters are related to :
- If
Erroneous_Data_ReportingParameter set todisable, bePacket_Status_FlagField set to 00 - If
Erroneous_Data_ReportingParameter set toenable, bePacket_Status_FlagFields are set according to the following table

- Data_Total_Length Field

8.4 HCI Connection package example
HCI Connect command flow :
1) The Bluetooth protocol stack sends the connection command to the chip :HCI Connect command
2) The Bluetooth chip reports the command status to the Bluetooth protocol stack :HCI Command Complete
3) After successful connection , Bluetooth chip reports the successful connection event of Bluetooth protocol stack :HCI LE Connect complete
8.4.1 HCI Connect command
Core5.0 P774
This command is used to make Link Manager Link manager to connect remote devices .
Connect command The packet format is as follows :

OCF: Here you can see OCF Value , that OGF How much is it worth ?
open
Core5.0 P774, We can seeHCI_Create_ConnectionThe order belongs toLINK CONTROL COMMANDSLink control command group , This group OGF by 0x01. SeeCore5.0 P766For the Link Control commands, the OGF is defined as 0x01.
BD_ADDR: To connect the remote Bluetooth address of the device ,6 Bytes .
Packet_Type: Supported packet types ,2 Bytes .

Page_Scan_Repetition_Mode: Whether to repeat scanning

Clock_Offset: Clock offset between master and slave devices .

Allow_Role_Switch: Whether master-slave role conversion is supported

8.4.2 Command Complete Event
When Controller Received Create_Connection command , Will send a Command Complete Event to Host.
The event format is as follows :

This event is used to return the status after most commands are sent .
Event Code: Event code
Num_HCI_Command_Packets: Set up Host It can be sent to Controller Number of command packages , If not , Is set to 0

Command_Opcode: Indicates the corresponding command code

Return_Parameters: Return the parameters specified by the command

8.4.3 Connection Complete Event
This event shows Host And Controller The connection channel between is established successfully .

Event Code: Event code
Status: Connection status

Connection_Handle: After successful connection , Generated Handle value

BD_ADDR: After successful connection MAC Address

Link_Type: Connection type

Encryption_Enabled: Is it encrypted

These parameters are not necessarily required , Here's the catch HCI package , I hope it helps .


All right. , The above is the Bluetooth Protocol HCI Detailed introduction of the interface , After a detailed understanding , We have analysis HCI The basic capability of data package !

边栏推荐
- 技术选型Rust——事后分析
- 磷脂偶联抗体/蛋白试剂盒的存储与步骤
- 作价11.5亿元,1206件设备注入合资公司!SK海力士抢食大陆晶圆代工市场!
- Pytorch学习记录(四):过拟合、卷积神经网络CNN
- 百度搜索符合预期,但涉及外链黑帽策略,什么原因?
- Leetcode linked list question - interview question 02.07. linked list intersection (learn linked list by one question and one article)
- Bully is filed for bankruptcy! The company has become a "Lao Lai", and the legal person is restricted from high consumption
- MySQL 是如何归档数据的呢?
- CVPR 2022 | 网络中批处理归一化估计偏移的深入研究
- 工业通讯领域的总线、协议、规范、接口、数据采集与控制系统
猜你喜欢

比UUID更快更安全NanoID到底是怎么实现的?(荣耀典藏版)

编码用这16个命名规则能让你少写一半以上的注释!

基于Xilinx的时序分析与约束

MySQL 是如何归档数据的呢?

How to measure software architecture

LT7911D Type-C/DP转mipi 方案成熟可提供技术支持

Achieve waterfall effect

Attribute based encryption simulation and code implementation (cp-abe) paper: ciphertext policy attribute based encryption

Maintenance of delta hot metal detector principle analysis of v5g-jc-r1 laser measurement sensor / detector

Api 接口优化的几个技巧
随机推荐
System integration under microservice architecture
LeetCode·581.最短无序连续子数组·双指针
蚂蚁集团境外站点 Seata 实践与探索
不用Swagger,那我用啥?
Achieve waterfall effect
比UUID更快更安全NanoID到底是怎么实现的?(荣耀典藏版)
Uncaught Error:Invalid geoJson format Cannot read property ‘length‘ of undefind
探讨:想要落地DevOps的话,只考虑好的PaaS容器平台就够了么?
中国农业工程学会农业水土工程专业委员会-第十二届-笔记
MySQL
CVPR 2022 | 网络中批处理归一化估计偏移的深入研究
到底为什么不建议使用SELECT * ?
Explain C language 12 in detail (C language series)
Kubeadm搭建kubernetes集群
八、QOS队列调度与报文丢弃
Timing analysis and constraints based on Xilinx
Summary of 29 typical problems in Devops planning and construction of securities enterprises based on containerized PAAS platform
Four methods of multi-threaded sequential operation. Ask casually during the interview
Api 接口优化的几个技巧
怎么理解数据网格(Data Mesh)