Bluetooth: att protocol

一篇搞懂 ATT 支持的东西都有什么。

READ_BY_GROUP_TYPE_REQ/RSP

如下是 Spec 内容:
The attributes returned shall be the attributes with the lowest handles within the handle
range. These are known as the requested attributes.

If the attributes with the requested type within the handle range have attribute
values that have the same length, then these attributes can all be read in a
single request. However, if those attributes have different lengths, then multiple
ATT_READ_BY_GROUP_TYPE_REQ PDUs must be issued.

The ATT Server shall include as many attributes as possible in the response in order to
minimize the number of PDUs required to read attributes of the same type.

翻译一下:
不是逐字逐句的翻译哈,将其表达的意思说明清楚:
按照查找的范围,找到符合type的所有attibute 的 handle + value + group_end_handle;
因为 value 的长度可能会各有区别,每个 RSP packet 需要将相同长度的放在一起才可以;
但是考虑到 MTU 的限制,有时必须要进行多次请求回应才可以拿到所需范围内的attibutes;
实际中,往往是这样来实现:这些找到的attributes按照handle从小打到排列,例如 group_end_handle<=20的,其value都是同样长度,那么就先回应出去;然后对方下一个请求的起始handle就会从21开始,Server收到后,发现21 ~ group_end_handle 为80 的attributes 的 value都是同样的长度,那么就再回应出去,以此类推。

READ_BY_TYPE/RSP

来自于 Spec:
The attributes returned shall be the attributes with the lowest handles within the handle
range. These are known as the requested attributes

If the attributes with the requested type within the handle range have attribute
values that have the same length, then these attributes can all be read in a
single request. However, if those attributes have different lengths, then multiple
ATT_READ_BY_TYPE_REQ PDUs must be issued.

The ATT Server shall include as many attributes as possible in the response in order to
minimize the number of PDUs required to read attributes of the same type.

翻译下:
基本和前面 READ_BY_GROUP 一样;
可以发现 READ_BY_GROUP Response 会多出来 end_group_hanlde;

FIND_INFORMATION_REQ/RSP

来自 Spec:
If sequential attributes have differing UUID sizes, the ATT_FIND_INFORMATION_RSP
PDU shall end with the first attribute of the pair even though this may mean that it is not
filled with the maximum possible amount of (handle, UUID) pairs. This is because it is
not possible to include attributes with differing UUID sizes into a single response packet.
In this situation, the client must use another ATT_FIND_INFORMATION_REQ PDU with
its starting handle updated to fetch the second attribute of the pair and any further ones
in its original request.

翻译下:
也是和 READ_BY_GROUYP 一样;
这个请求只是获取了 attribute 的 handle 和 type,没有得到 value;

FIND_BY_TYPE_VALUE_REQ/RSP

READ_REQ/RSP

来自 Spec:
If the attribute value is longer than (ATT_MTU-1) then the first (ATT_MTU-1) octets shall be included in this response.

Note: The ATT_READ_BLOB_REQ PDU can be used to read the remaining octets of a long attribute value.

翻译下:
如果 attribute 的 value 超过MTU-1, 那么第一个 MTU-1 的包一定是 READ_RSP, 后面跟着的才是 READ_BLOB_RSP

READ_BLOB_REQ/RSP

来自 Spec:
The value offset parameter is based from zero; the first value octet has an offset of zero,
the second octet has a value offset of one, etc.

If the long attribute has a variable length, the only way to get to the end
of it is to read it part by part until the value in the ATT_READ_BLOB_RSP PDU has a
length shorter than (ATT_MTU-1) or an ATT_ERROR_RSP PDU is sent with the Error
Code parameter set to Invalid Offset (0x07).

The part attribute value shall be set to part of the value of the attribute identified by the attribute handle and the value offset in the request. If the value offset is equal to the length of the attribute value, then the length of the part attribute value shall be zero. If the attribute value is longer than (Value Offset + ATT_MTU-1) then (ATT_MTU-1) octets from Value Offset shall be included in this response.

翻译下:
offset 要从 0开始,而不是从 之前的 READ_RSP 或者 NOTIFY 或者 INDICATION 的 包长度推测;
这里提到了一种如何知道已经读完了整个value,要么是 READ_BLOP_RSP 的长度小于 MTU-1,要么是收到offset 错误;
另外如果 offset 已经 间接标识了 整个value 读完了,此时 READ_BLOB_RSP 的value要是0长度;

READ_MULTIPLE_REQ/RSP

来自 Spec:
Only values that have a known fixed size can be read, with the exception of the last value that can have a variable length.

Note: The attribute values for the attributes in the Set Of Handles parameters do not
have to all be the same size.

Note: The attribute handles in the Set Of Handles parameter do not have to be in
attribute handle order; they are in the order that the values are required in the response.

The Set Of Values parameter shall be a concatenation of attribute values for each of
the attribute handles in the request in the order that they were requested. If the Set Of
Values parameter is longer than (ATT_MTU-1) then only the first (ATT_MTU-1) octets
shall be included in this response.

Note: A client should not use this request for attributes when the Set Of Values
parameter could be (ATT_MTU-1) as it will not be possible to determine if the last
attribute value is complete, or if it overflowed.

翻译下:
请求多个handle 的value,所以对方最好是清楚知道每个handle的value 长度;回复是按照 handle在 request中出现的顺序,依次就行连接形成的包;
回应包长度不能超过MTU-1;

READ_MULTIPLE_VARIABLE_REQ/RSP

WRITE_REQ/RSP

WRITE_CMD

SIGNED_WRITE_CMD

PREPARE_WRITE_REQ/RSP

EXCUTE_WRITE_REQ

HANDLE_VALUE_NTF

来自 Spec:
If the attribute value is longer than (ATT_MTU-3) octets, then only the first (ATT_MTU-3)
octets of this attributes value can be sent in a notification.

Note: For a client to get a long attribute, it must use the ATT_READ_BLOB_REQ PDU following the receipt of this notification.

翻译下:
对于长度超过 MTU-3 的 attribute value,client接下来也要用 READ_BLOB_REQ 获取其他剩余;

HANDLE_VALUE_IND/CFM

来自 Spec:
If the attribute value is longer than (ATT_MTU-3) octets, then only the first (ATT_MTU -
3) octets of this attributes value can be sent in an indication.

Note: For a client to get a long attribute, it must use the ATT_READ_BLOB_REQ PDU following the receipt of this indication.

翻译下:
长度超过 MTU-3时,client接下来用 READ_BLOB_REQ 来获取;

MULTIPLE_HANDLE_VALUE_NTF

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值