本文介绍了蓝牙LE的最大封包长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道蓝牙低功耗中最大的数据包长度是多少.对于此处的示例

I was wondering what was the maximum packet length in Bluetooth Low Energy. The 20 bytes limit if often said, for example here

您是对的,BLE规范不允许写操作超过20个字节."

"You are correct that the BLE specification doesn't allow write operations to exceed 20 bytes."

但是,通过阅读Bluetooth Core规范,我们可以看到ATT_MTU值写入了2个字节,这意味着它可以增加到65 535个字节.

However, reading the Bluetooth Core Specification, we can see that the ATT_MTU value is written with 2 bytes, meaning that it can go up to 65 535 bytes.

这一切背后的真相是什么?

What's the truth behind all this ?

推荐答案

规范总是正确的!

在蓝牙4.0中,引入了BLE,最大有效负载为33字节(不包括访问地址和CRC字段).协议栈中的每一层都有自己的特色:

In Bluetooth 4.0, BLE was introduced with a maximum payload of 33 bytes (not including Access Address and CRC fields). Each layer in the protocol stack takes its cut:

  • 2个字节的数据包头(类型和长度),
  • 4个MIC字节(启用加密后),
  • L2CAP标头的4个字节(通道ID和数据包长度),
  • ATT协议剩余23个字节,这是ATT协议的默认值和最小MTU.

对于ATT写入请求(或通知),命令类型和属性ID使用3个字节,属性数据剩下 20个字节.

With an ATT write request (or notification), 3 bytes are used by command type and attribute ID, 20 bytes are left for the attribute data.

在ATT级别,可以通过两种方式扩大此限制:

At the ATT level, this limit may be enlarged in two ways:

  • 在L2CAP级别使用分段:

  • Using fragmentation at the L2CAP level:

L2CAP将ATT PDU分成27个字节的片段(第一个为23个).

L2CAP will split ATT PDUs in 27 bytes fragments (23 for the first one).

缺点:

  • 它需要双方记忆,
  • 它的可靠性较差,因为某些实现可能会丢失数据包(即使规范未提及L2CAP级别的数据包丢失,也会发生这种情况)

使用蓝牙4.2中引入的数据包长度扩展:

Using packet length extension introduced in Bluetooth 4.2:

在无线电级别上最多251个字节(带MIC时为255个字节),因此242个字节可用于属性数据.

Up to 251 bytes at the radio level (255 with MIC), so 242 bytes available for attribute data.

缺点:

  • 仍是新事物,需要硬件支持,因此并非在所有地方都实现(即使宣布支持BLE 4.2),

  • Still new, needs hardware support, so not implemented everywhere (even if announcing BLE 4.2 support),

具有较长广播时间的数据包将更有可能被阻塞,因此,较长的数据包意味着更多的重传.

Packet with longer airtime will have more chances of getting jammed, so longer packets implies more retransmissions.

如果同时使用这两种方法,则L2CAP可能会使用更大的片段.

If both methods are used, L2CAP may use bigger fragments.

无论ATT PDU的低级分割如何,属性值的长度都被3.F 3.2.9限制为512.

Whatever low-level splitting of ATT PDU, Attribute value length is limited to 512 by 3.F 3.2.9.

这篇关于蓝牙LE的最大封包长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 18:38