第一部分:HCI协议(八)具体的HCI command和event(16、AUTHENTICATION AND ENCRYPTION 一)
上面两个命令没明白
(1)Link Key Request Event
收到这个event表示与BD_ADDR的连接需要一个Link Key,如果host有对应的 Link Key,host需要使用Link_Key_Request_Reply将这个Link Key发送给Controller,如果host没有对应的Link Key,host需要使用Link_Key_Request_Negative_Reply进行回复
注意:需要在LMP response timeout之前回复
If the Host uses the Link_Key_Request_Negative_Reply command when the
requested service requires an authenticated Link Key and the current Link Key
is unauthenticated, the Host should set the Authentication_Requirements
parameter one of the MITM Protection Required options.
参数说明:
BD_ADDR(6 Octet):远端设备地址
举例说明:
0x04:表示HCI Event Packet
0x17:表示这个event是Link Key Request event
0x06:表示Parameter_Total_Length即6个byte
0xe1 0x99 0xce 0x0a 0xcc 0x66:表示远端设备地址是0xcc 0x66 0x0a 0xce 0x99 0xe1
(2)Link Key Request Reply Command
当收到Link Key Request event时,如果host保存有跟BD_ADDR相关的Link key则可以使用这个命令进行回复
注意:需要在LMP response timeout之前回复
When the BR/EDR Controller supports the Secure Connections (Controller
Support) feature, it shall discard the Link Key once the connection has been
disconnected.
参数说明:
BD_ADDR(6 Octet):远端设备地址
Link_Key(16 Octet):与BD_ADDR相关的link key
返回参数说明:
Status(1 Octet):0x00表示成功,其他值表示失败
BD_ADDR(6 Octet):远端设备地址
举例说明:
Command如下:
0x01:表示HCI Command Packet
0x040B:表示是HCI_Link_Key_Request_Reply command
指令的OGF是0x01即0000 01
OCF是0x000B即00 0000 1011
所以整个opcode是0000 0100 0000 1011即0x040B
0x16:表示Parameter_Total_Length=0x16,即参数总长度是22个byte
0xe1 0x99 0xce 0x0a 0xcc 0x66:表示远端设备地址是0xcc 0x66 0x0a 0xce 0x99 0xe1
Link Key: 0xf1 0x4f 0x26 0x9b 0x00 0x3f 0x3b 0x88 0x85 0x95 0x79 0x20 0x66 0x71 0x3d 0x39
对应的Event:
Command Complete event:
0x04:表示HCI Event Packet
0x0e:表示这个event是command complete event
0x0a:表示Parameter_Total_Length即10个byte
0x01:表示Num_HCI_Command_Packets
0x040b:表示是HCI_Link_Key_Request_Reply command
0x00:表示status为0
0xe1 0x99 0xce 0x0a 0xcc 0x66:表示远端设备地址是0xcc 0x66 0x0a 0xce 0x99 0xe1
(3)Link Key Request Negative Reply Command
如果host没有对应BD_ADDR的Link Key,host需要使用Link_Key_Request_Negative_Reply进行回复
注意:需要在LMP response timeout之前回复
参数说明:
BD_ADDR(6 Octet):远端设备地址
返回参数说明:
Status(1 Octet):0x00表示成功,其他值表示失败
BD_ADDR(6 Octet):远端设备地址
举例说明:
Command如下:
0x01:表示HCI Command Packet
0x040C:表示是HCI_Link_Key_Request_Negative_Reply command
指令的OGF是0x01即0000 01
OCF是0x000C即00 0000 1100
所以整个opcode是0000 0100 0000 1100即0x040C
0x6:表示Parameter_Total_Length=0x6,即参数总长度是6个byte
0x35 0x8b 0xf8 0x11 0x1a 0xfc:表示远端设备地址是0xfc 0x1a 0x11 0xf8 0x8b 0x35
对应的Event:
Command Complete event:
0x04:表示HCI Event Packet
0x0e:表示这个event是command complete event
0x0a:表示Parameter_Total_Length即10个byte
0x01:表示Num_HCI_Command_Packets
0x040c:表示是HCI_Link_Key_Request_Negative_Reply command
0x00:表示status为0
0x35 0x8b 0xf8 0x11 0x1a 0xfc:表示远端设备地址是0xfc 0x1a 0x11 0xf8 0x8b 0x35
(1)PIN Code Request Event
远端设备发起PIN Code配对时,controller会发送给host这个event,PIN Code Request event表示需要一个PIN code来产生一个新的link key,host收到这个event后,需要回复PIN_Code_Request_Reply(有PIN Code)或者 PIN_Code_Request_Negative_Reply(没有PIN Code)
注意:需要在LMP response timeout之前回复
参数说明:
BD_ADDR(6 Octet):远端设备地址
举例说明:
0x04:表示HCI Event Packet
0x16:表示这个event是PIN Code Request event
0x06:表示Parameter_Total_Length即6个byte
0x35 0x8b 0xf8 0x11 0x1a 0xfc:表示远端设备地址是0xfc 0x1a 0x11 0xf8 0x8b 0x35
(2)PIN Code Request Reply Command
当host收到PIN Code request event时,可以使用PIN_Code_Request_Reply command来回复PIN Code
注意:需要在LMP response timeout之前回复
参数说明:
BD_ADDR(6 Octet):远端设备地址
PIN_Code_Length(1 Octet):表示PIN Code的长度
PIN_Code(16 Octet):用来配对的PIN Code,这是一个string类型的参数,
返回参数说明:
Status(1 Octet):0x00表示成功,其他值表示失败
BD_ADDR(6 Octet):远端设备地址
举例说明:
Command如下:
0x01:表示HCI Command Packet
0x040D:表示是HCI_PIN_Code_Request_Reply command
指令的OGF是0x01即0000 01
OCF是0x000C即00 0000 1101
所以整个opcode是0000 0100 0000 1101即0x040D
0x17:表示Parameter_Total_Length=0x17,即参数总长度是23个byte
0x35 0x8b 0xf8 0x11 0x1a 0xfc:表示远端设备地址是0xfc 0x1a 0x11 0xf8 0x8b 0x35
0x04:表示PIN_Code_Length=4 byte
PIN Code:0x30 0x30 0x30 0x30 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00即字符串0000
对应的Event:
Command Complete event:
0x04:表示HCI Event Packet
0x0e:表示这个event是command complete event
0x0a:表示Parameter_Total_Length即10个byte
0x01:表示Num_HCI_Command_Packets
0x040D:表示是HCI_PIN_Code_Request_Reply command
0x00:表示status为0
0x35 0x8b 0xf8 0x11 0x1a 0xfc:表示远端设备地址是0xfc 0x1a 0x11 0xf8 0x8b 0x35
(3)PIN Code Request Negative Reply Command
当host不能提供PIN Code时可以使用这个命令回复,即拒绝配对的时候
注意:需要在LMP response timeout之前回复
参数说明:
BD_ADDR(6 Octet):远端设备地址
返回参数说明:
Status(1 Octet):0x00表示成功,其他值表示失败
BD_ADDR(6 Octet):远端设备地址
举例说明:(暂时没有)