内容资料来源于 Bluetooth Core Specification v5.4 Vol 3 Part A:Logical link control and adaptation layer protocol specification
1、L2CAP(Logical link control and adaptation layer protocol)
2、功能:多路复用、分段重组
3、架构
4、基本概念
(1)SDU(service data unit),从上层协议或应用传来的数据
(2)PDU(protol data unit),l2cap封装后的数据,PDU的类型有B-frame、I-frame、S-frame、C-frame、G-frame、K-frame
(3)MTU(maximum Transmission Unit), SDU的最大长度
(4)MPS(Maximum PDU payload Size),PDU负载的最大长度
(5)CID(channl identifier),l2cap通道id
(6)MaxTransmit,重传模式和增强重传模式中的最大重传次数
5、传输模式
(1)Basic L2CAP Mode,默认模式,没有流控制,也没有重传,只是收发
(2)Flow Control Mode,流控制模式,不会重传,但可检测到数据丢失
(3)Retransmission Mode,重传模式,有流控制,也会重传
(4)Enhanced Retransmission Mode, 增强重传模式
(5)Streaming Mode,流模式,实时传输,无ack
(6)LE Credit Based Flow Control Mode,(LE的,不管)
(7)Enhanced Credit Based Flow Control Mode,(LE的,不管)
6、L2CAP通道
7、PDU
(1)B-frame,面向连接的通道的数据格式(通道已建立连接),用来传输数据。
(2)G-frame,面向无连接的通道数据格式(通道未连接),用来发送广播数据、发送定向广播数据(指定某个设备的广播数据)
0x0002:固定为0x0002的CID
PSM:Protocol/Service Multiplexer,上层每个协议都会有一个唯一且固定的PSM,相当于上层协议的编号。
(3)C-frame,信号数据格式,用来收发命令的,格式和B-frame一样,但payload有具体规定
payload:
--code:命令类型,可取值如下
--identifier:1个字节,用来匹配命令和回复的,命令和回复中该字节的值应当是相同的
(4)I-frame,用来支持流控制模式(flow control),重传模式(retransmission)和流模式(streaming),详情看相关模式章节
(5)S-frame,S-frames are used to acknowledge I-frames and request retransmission of
![](https://img-blog.csdnimg.cn/direct/34d5e86cff61494a9be0a9e9463e3bd2.png)
![](https://img-blog.csdnimg.cn/direct/5c127ff0e0b94fa0bd83958a344d0785.png)
8、L2CAP命令(C-frame里面payload内容)
Reason:被拒绝的原因,可取值如下
Reason data
![](https://img-blog.csdnimg.cn/direct/e78eae115cdb4961bd762bb01b24b158.png)
![](https://img-blog.csdnimg.cn/direct/c69cf36eeec345098e7dd8bcf45ccd07.png)
![](https://img-blog.csdnimg.cn/direct/9bc837622a7b4447882c19301c346039.png)
![](https://img-blog.csdnimg.cn/direct/3c738b10843a46c88a127d7cff06505f.png)
![](https://img-blog.csdnimg.cn/direct/59b831e9e7084265826c2d729f36b535.png)
![](https://img-blog.csdnimg.cn/direct/3dcec3338e304fadaac117a898fb927e.png)
![](https://img-blog.csdnimg.cn/direct/e9a2033596e442a5a34e65062094259a.png)
![](https://img-blog.csdnimg.cn/direct/daf37876cdfc4f648b8d363a536c850e.png)
![](https://img-blog.csdnimg.cn/direct/50aaeb67db8441e88195bb97eeec4c53.png)
9、configuration
Flags:只有最低位(bit)是有用的,表明是否支持Extend Flow Specification option
configuration options:
![](https://img-blog.csdnimg.cn/direct/928bb66575fb40b79f19bcd176330bae.png)
![](https://img-blog.csdnimg.cn/direct/a367e817110240b59b959a92f5427a10.png)