3、普通配对时使用的command(认证失败后开始配对)
(1)PIN Code Request Event(常用)
Host回复Link Key Request Negative Reply Command后或者对方发起普通配对时会收到这个ecommand。
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):远端设备地址
举例说明:(暂时没有)
(4)Link Key Notification Event(常用)
当controller发送Link Key Notification event给host时,表示本地设备与地址为BD_ADDR的远端设备之间的连接已经产生了一个新的Link key,此时host可以将这个Link key存起来,也可以使用Write_Stored_Link_Key将link key存到controller内。
参数说明:
BD_ADDR(6 Octet):远端设备地址
Link_Key(16 Octet):与BD_ADDR相关的link key
Key_Type(1 Octet):取值范围如下:
使用普通配对方式(PIN Code)时,Key_Type可能是0x00,0x01,0x02
使用Simple Pairing方式时,Key_Type可能是0x03,0x04,0x05,0x07,0x08
Debug Combination Key:使用Simple Pairing模式时,并且接收或者发送debug public key
举例说明:
0x04:表示HCI Event Packet
0x18:表示这个event是Link Key Notification event
0x17:表示Parameter_Total_Length即23个byte
0x35 0x8b 0xf8 0x11 0x1a 0xfc:表示远端设备地址是0xfc 0x1a 0x11 0xf8 0x8b 0x35
Link Key:0xdf 0x99 0xbf 0x71 0xa7 0xbb 0x70 0xb6 0x88 0xbe 0x55 0x6e 0x4b 0x01 0x31 0xee
0x00:表示key_type是Combination Key