技术标签: HCI command HCI命令 # 蓝牙协议栈精讲 # 蓝牙协议剖析 蓝牙HCI
本专栏文章我们会以连载的方式持续更新,本专栏计划更新内容如下:
第一篇:蓝牙综合介绍 ,主要介绍蓝牙的一些概念,产生背景,发展轨迹,市面蓝牙介绍,以及蓝牙开发板介绍。
第二篇:Transport层介绍,主要介绍蓝牙协议栈跟蓝牙芯片之前的硬件传输协议,比如基于UART的H4,H5,BCSP,基于USB的H2等
第三篇:传统蓝牙controller介绍,主要介绍传统蓝牙芯片的介绍,包括射频层(RF),基带层(baseband),链路管理层(LMP)等
第四篇:传统蓝牙host介绍,主要介绍传统蓝牙的协议栈,比如HCI,L2CAP,SDP,RFCOMM,HFP,SPP,HID,AVDTP,AVCTP,A2DP,AVRCP,OBEX,PBAP,MAP等等一系列的协议吧。
第五篇:低功耗蓝牙controller介绍,主要介绍低功耗蓝牙芯片,包括物理层(PHY),链路层(LL)
第六篇:低功耗蓝牙host介绍,低功耗蓝牙协议栈的介绍,包括HCI,L2CAP,ATT,GATT,SM等
第七篇:蓝牙芯片介绍,主要介绍一些蓝牙芯片的初始化流程,基于HCI vendor command的扩展
第八篇:附录,主要介绍以上常用名词的介绍以及一些特殊流程的介绍等。
另外,开发板如下所示,对于想学习蓝牙协议栈的最好人手一套。以便更好的学习蓝牙协议栈,相信我,学完这一套视频你将拥有修改任何协议栈的能力(比如Linux下的bluez,Android下的bluedroid)。
------------------------------------------------------------------------------------------------------------------------------------------
CSDN学院链接(进入选择你想要学习的课程):https://edu.csdn.net/lecturer/5352?spm=1002.2001.3001.4144
蓝牙交流扣扣群:970324688
Github代码:https://github.com/sj15712795029/bluetooth_stack
入手开发板:https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-22329603896.18.5aeb41f973iStr&id=622836061708
------------------------------------------------------------------------------------------------------------------------------------------
在介绍蓝牙command之前我还是要啰嗦点,尽管前面的文章已经写了,但是不排除有人直接看到这份文档
HCI命令包用于从协议栈发送给芯片的命令。HCI命令包的格式如下图所示:
Opcode:每个命令被分配一个2字节的操作码(opcode),用来唯一地识别不同类型的命令,操作码(opcode)参数分为两个字段,称为操作码组字段(Opcode Group Field, OGF)和操作码命令字段(Opcode Command Field, OCF)。其中OGF占用高6bit字节,OCF占用低10bit字节。
一共有以下几组OGF:
1)Link Control commands, the OGF is defined as 0x01.链路控制OGF,也就是控制蓝牙芯片跟remote沟通的命令
2)Link Policy commands, the OGF is defined as 0x02,链路策略OGF,也就是写一些Policy,比如转换角色等
3)HCI Control and Baseband commands, the OGF is defined as 0x03,控制本地芯片跟基带的OGF。比如reset本地芯片等。
4)Informational Parameters commands, the OGF is defined as 0x04。读取信息的OGF,比如读取本地芯片的LMP版本呢,支持的command,蓝牙地址等,
5)status parameters commands, the OGF is defined as 0x05,状态参数OGF,比如读取RSSI等。
6)Testing commands, the OGF is defined as 0x06,测试命令的OGF,比如让芯片进入测试模式(DUT,device under test)
7)LE Controller commands, the OGF code is defined as 0x08,BLE 的comand
8)vendor-specific debug commands,the OGF code is defined as 0x3F,此部分是vendor定义的,也就是芯片厂商为了扩展core文档的HCI command定义
OCF众多,在每个OGF下都有一堆的OCF定义
Parameter Total Length:后续参数的长度
Parameter:每个command的para不同,下个小节做说明
注意:HCI Command Packet的长度不能超过255(包括HCI Command包头)
下面我们就列下常用的一堆HCI command,待后续补充
传统蓝牙HCI 命令(部分) | |||
列1 | 列2 | 列3 | 列4 |
OGF | OCF | 命令 | 命令描述 |
Link Control command(0x01) | 0x0001 | Inquiry command | 让BR/EDR芯片进行搜索模式,搜索周边的BR/EDR设备 |
0x0002 | Inquiry Cancel command | 如果BR/EDR芯片在搜索状态,那么停止BR/EDR芯片的搜索 | |
0x0003 | Periodic Inquiry Mode command | 让BR/EDR芯片进入周期搜索状态,但是此命令不常用,并且有的芯片会返回错误,所以不在此处扩展讲解 | |
0x0004 | Exit Periodic Inquiry Mode command | 让进入周期搜索状态的BR/EDR蓝牙芯片退出周期搜索状态 | |
0x0005 | Create Connection command | 根据参数跟特定的蓝牙地址创建连线 | |
0x0006 | Disconnect command | 根据参数跟特定的连接句柄断开连接,可以用来断开ACL,也可以用来断开SCO,eSCO等等 | |
0x0008 | Create Connection Cancel command | “连接中”的取消指令,此功能感觉比较鸡肋,同样我也没用过 | |
0x0009 | Accept Connection Request command | 接受连接请求 | |
0x000A | Reject Connection Request command | 拒绝连接请求 | |
0x000B | Link Key Request Reply command | 对方请求linkkey的时候,而我们有此link key,我们回复link key | |
0x000C | Link Key RequestNegative Reply command | 对方请求linkkey的时候,而我们没有次link key的情形下回复 | |
0x000D | PIN Code Request Reply command | 用于应答芯片发送的pincode申请,并把pincode用于连线 | |
0x000E | PIN Code RequestNegative Reply command | 不能用于pincode连线 | |
0x000F | Change Connection Packet Type command | 改变正在连接的交互封包类型 | |
0x0011 | Authentication Requested command | 用于指令连接句柄的两个蓝牙地址进行身份认证 | |
0x0013 | Set Connection Encryption command | 建立或者取消连接层次的加密 | |
0x0015 | Change Connection Link Key command | 用于指定额链接句柄,生成一组新的link key | |
0x0017 | Master Link Key command | 用于强制主设备使用主设备的临时或半永久link key | |
0x0019 | Remote Name Request command | 获取远端设备名称 | |
0x001A | Remote Name Request Cancel command | 取消获取远端设备名称 | |
0x001B | Read Remote Supported Features command | 获取remote端支持的feature | |
0x001C | Read Remote Extended Features command | 获取remote端支持的扩展feature | |
0x001D | Read Remote Version Information command | 获取remote端版本信息,注意此部分是LMP或者LL的版本 | |
0x001F | Read Clock Offset command | 获取时钟偏移 | |
0x0020 | Read LMP Handle command | 获取LMP句柄 | |
0x0028 | Setup Synchronous Connection command | 建立SCO | |
0x0029 | Accept Synchronous Connection Request command | 接受对方SCO建立请求 | |
0x002A | Reject SynchronousConnection Request command | 拒绝对方SCO建立请求 | |
0x002B | IO Capability Request Reply command | 当在SSP配对模式下,响应芯片IO capability的请求 | |
0x002C | User Confirmation Request Reply command | 当在SSP配对模式下,响应芯片IO User Confirmation的请求 | |
0x002D | User Confirmation Request Negative Reply command | 当在SSP配对模式下,拒绝芯片IO User Confirmation的请求 | |
0x0034 | IO Capability RequestNegative Reply command | 当在SSP配对模式下,拒绝芯片IO capability的请求 | |
Link Policy commands (0x02) | 0x0001 | Hold Mode command | 用于更改链接的行为,并让它将指定的Connection_Handle关联的ACL基带连接放置到Holdmode中 |
0x0003 | Sniff Mode command | 用于改变该链接的行为管理并让它将与指定Connection_Handle关联的ACL基带连接置于嗅探模式 | |
0x0004 | Exit Sniff Mode command | 离开嗅探模式 | |
0x0007 | QoS Setup command | 用于为Connection_Handle指定服务质量参数 | |
0x0009 | Role Discovery command | 查询当前的连线芯片处于什么角色 | |
0x000B | Switch Role command | 进行角色切换 | |
0x000C | Read Link Policy Settings command | 读取当前connection_handle的连接策略 | |
0x000D | Write Link Policy Settings command | 改变当前连线的连接策略 | |
0x000E | Read Default Link Policy Settings command | 读取默认的连接策略 | |
0x000F | Write Default Link Policy Settings command | 改变当前默认的连接策略 | |
0x0010 | Flow Specification command | 用于指定通过Connection_Handle标识的ACL Connection_Handle传输的流量的流参数 | |
0x0011 | Sniff Subrating command | 为给定链接指定用于嗅探子例程的参数 | |
Control and Baseband commands(0x03) | 0x0001 | Set Event Mask command | 用于控制HCI为主机生成哪些事件 |
0x0003 | Reset command | reset蓝牙芯片(软复位) | |
0x0005 | Set Event Filter command | 设置事件过滤 | |
0x0008 | Flush command | 丢弃芯片中正在等待传输的数据 | |
0x0009 | Read PIN Type command | 读取PIN 类型 | |
0x000A | Write PIN Type command | 写PIN类型 | |
0x000D | Read Stored Link Key command | 读取芯片中存储的Link key | |
0x0011 | Write Stored Link Key command | 把link key写入到芯片中 | |
0x0012 | Delete Stored Link Key command | 删除芯片中的Link key | |
0x0013 | Write Local Name command | 写入本地名称到芯片中 | |
0x0014 | Read Local Name command | 读取芯片的蓝牙名称 | |
0x0015 | Read Connection Accept Timeout command | 读取蓝牙连接接收的超时时间 | |
0x0016 | Write Connection Accept Timeout command | 写入蓝牙连接接收的超时时间 | |
0x0017 | Read Page Timeout command | 读取page的超时时间 | |
0x0018 | Write Page Timeout command | 写page的超时时间 | |
0x0019 | Read Scan Enable command | 读取scan enable | |
0x001A | Write Scan Enable command | 写scan enable | |
0x001B | Read Page Scan Activity command | 读取Page Scan Activity | |
0x0023 | Read Class of Device command | 读取芯片的cod | |
0x0024 | Write Class of Device command | 把cod写入cod | |
0x0025 | Read Voice Setting command | 读取voice setting | |
0x0026 | Write Voice Setting command | 把voice setting写入到芯片 | |
0x0031 | Set Controller To Host Flow Control command | 启动HCI 流控 | |
0x0033 | Host Buffer Size command | 把buffer size写入到芯片中 | |
0x0036 | Read Link Supervision Timeout command | 读取Link Supervision timeout时间(也就是Link lost时间) | |
0x0037 | Write Link Supervision Timeout command | 把Link Supervision timeout写入到芯片(也就是Link lost时间) | |
0x0044 | Read Inquiry Mode command | 读取芯片的搜索模式 | |
0x0045 | Write Inquiry Mode command | 把搜索模式写入到芯片中 | |
0x0051 | Read Extended Inquiry Response command | 读取芯片的Extended inquiry response | |
0x0052 | Write Extended Inquiry Response command | 把Extended inquiry response写入到芯片 | |
0x0055 | Read Simple Pairing Mode command | 读取芯片是否支持SSP | |
0x0056 | Write Simple Pairing Mode command | 把是否支持SSP写入到蓝牙芯片 | |
Informational Parameters commands (0x04) |
0x0001 | Read Local Version Information command | 读取本地芯片的LMP version |
0x0002 | Read Local Supported Commands command | 读取本地芯片支持的command | |
0x0003 | Read Local Supported Features command | 读取本地芯片支持的feature | |
0x0004 | Read Local Extended Features command | 读取本地芯片支持的扩展feature | |
0x0005 | Read Buffer Size command | 读取本地芯片的buffer size | |
0x0009 | Read BD_ADDR command | 读取本地芯片的蓝牙地址 | |
0x000A | Read Data Block Size command | 读取本地芯片的block size | |
0x000B/D | Read Local Supported Codecs command | 读取本地芯片支持的编码格式 | |
0x000C | Read Local Simple Pairing Options command | 读取本地SSP选项 | |
0x000E | Read Local Supported Codec Capabilities command | 读取本地芯片支持的codec capabilities | |
status parameters commands (0x05) |
0x0003 | Read Link Quality command | 读取连接质量 |
0x0005 | Read RSSI command | 读取接收信号强度 | |
0x0007 | Read Clock command | 读取clock | |
Testing commands (0x06) |
0x0001 | Read Loopback Mode command | 去读loopback模式 |
0x0002 | Write Loopback Mode command | 写loopback模式 | |
0x0003 | Enable Device Under Test Mode command | 使设备进去测试模式 |
文章浏览阅读1.1w次,点赞7次,收藏34次。vue-grid-layout的使用、实例、遇到的问题和解决方案_vue-grid-layout
文章浏览阅读218次。然后连接一个数据源,就会在下面自动产生一个添加附件的组件。把这个控件复制粘贴到页面里,就可以单独使用来上传了。插入一个“编辑”窗体。_powerapps点击按钮上传附件
文章浏览阅读264次。(1) Abstraction (抽象)(2) Polymorphism (多态)(3) Inheritance (继承)(4) Encapsulation (封装)_"object(cnofd[\"ofdrender\"])十条"
文章浏览阅读133次。删除node_modules,重新npm install看是否成功。在 package.json 文件中的 scripts 中加入。修改你的第三方库的bug等。然后目录会多出一个目录文件。_修改 node_modules
文章浏览阅读883次。【代码】【】kali--password:su的 Authentication failure问题,&sudo passwd root输入密码时Sorry, try again._password: su: authentication failure
文章浏览阅读1w次,点赞13次,收藏97次。整理5个优秀的微信小程序开源项目。收集了微信小程序开发过程中会使用到的资料、问题以及第三方组件库。_微信小程序开源模板
文章浏览阅读128次。Centos7最简搭建NFS服务器_centos7 搭建nfs server
文章浏览阅读1.2k次,点赞2次,收藏3次。前言mybatis在持久层框架中还是比较火的,一般项目都是基于ssm。虽然mybatis可以直接在xml中通过SQL语句操作数据库,很是灵活。但正其操作都要通过SQL语句进行,就必须写大量的xml文件,很是麻烦。mybatis-plus就很好的解决了这个问题。..._mybaitis-plus ruledataobjectattributemapper' and 'com.picc.rule.management.d
文章浏览阅读325次。EECE 1080C / Programming for ECESummer 2022Laboratory 4: Global Functions PracticePlagiarism will not be tolerated:Topics covered:function creation and call statements (emphasis on global functions)Objective:To practice program development b_eece1080c
文章浏览阅读53次。被同机房早就1年前就学过的东西我现在才学,wtcl。设要求的数为\(x\)。设当前处理到第\(k\)个同余式,设\(M = LCM ^ {k - 1} _ {i - 1}\) ,前\(k - 1\)个的通解就是\(x + i * M\)。那么其实第\(k\)个来说,其实就是求一个\(y\)使得\(x + y * M ≡ a_k(mod b_k)\)转化一下就是\(y * M ...
文章浏览阅读1.3k次。首先,问题是如何出现的?晚上复查代码,发现一个activity没有调用自己的ondestroy方法我表示非常的费解,于是我检查了下代码。发现再finish代码之后接了如下代码finish();System.exit(0);//这就是罪魁祸首为什么这样写会出现问题System.exit(0);////看一下函数的原型public static void exit (int code)//Added ..._android 手动杀死app,activity不执行ondestroy
文章浏览阅读894次。Q: SylixOS 版权是什么形式, 是否分为<开发版税>和<运行时版税>.A: SylixOS 是开源并免费的操作系统, 支持 BSD/GPL 协议(GPL 版本暂未确定). 没有任何的运行时版税. 您可以用她来做任何 您喜欢做的项目. 也可以修改 SylixOS 的源代码, 不需要支付任何费用. 当然笔者希望您可以将使用 SylixOS 开发的项目 (不需要开源)或对 SylixOS 源码的修改及时告知笔者.需要指出: SylixOS 本身仅是笔者用来提升自己水平而开发的_select函数 导致堆栈溢出 sylixos