Android|使用BlueZ Interface修改ACL连接Supervision timeout

作者: Sam (甄峰) sam_code@hotmail.com

背景:
Sam在做Bluetooth USB Dongle与Bluetooth RemoteControl连接的程序时。注意到当手柄断电时,需要20s时间才能够接收到Disconnect Event.(Error Code:timeout). Ray觉得这个时间太久。要求修改到5-6s.

实际上,因为Bluetooth是无线连接设备,所以有时会连接不上,Supervision的作用就是,ACL连接双方约定多长时间没有联系上算断开。

在读取文档:Host Controller Interface Functional Specification文档中HCICommands and Events-〉Controler & BaseBandCommand->Read Link Supervision Timeout+Write LinkSupervision Timeout中。发现可以修改这个timeout.

1. 读取Supervision Timeout.
Command:HCI_Read_Link_Supervision_Timeout
OCF:0x0036
CommandParameters:Connection_Handle
Return Parameters: Status,Connection_Handle, Link_Supervision_Timeout
这个Command用来读取Link supervision timeout. 这是个基于ACL Connect的Command.

Command Param: Connect_Handle

Return Parameters:
Status: 0x00 : Success。
other: ErrorCode
Connection_Handle:ACL Connect Handle
Link_Supervision_Timeout:
0x00: No Link_Supervision_Timeout
N : BaseBand slots.一个BaseBand Slot等于0.625个ms.


2. 设置Supervision Timeout.
Command: HCI_Write_Link_Supervision_Timeout
OCF:0x0037
Command Parameters: Connection_Handle,Link_Supervision_Timeout
Return Parameters: Status, Connection_Handle
这个命令用来设置Supervision Timeout.

    推荐阅读