您好,
我有两个关于加密配对的问题想要请教一下
1、我在初始设置时已经把配对后绑定选项设置成false了,但是使用手机成功连接后还是会自动绑定设备。设置的代码如下:
// Don't send a pairing request after connecting; the peer device must
//uint32_t passkey = 0; // passkey "000000"
// initiate pairing
uint8_t pairMode = GAPBOND_PAIRING_MODE_INITIATE;
// Use authenticated pairing: require passcode.
uint8_t mitm = TRUE;
// This device only has display capabilities. Therefore, it will display the
// passcode during pairing. However, since the default passcode is being
// used, there is no need to display anything.
uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
// Request bonding (storing long-term keys for re-encryption upon subsequent
// connections without repairing)
uint8_t bonding = FALSE;
uint8_t gapbondSecure = GAPBOND_SECURE_CONNECTION_NONE;//GAPBOND_SECURE_CONNECTION_ONLY ;
GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &gapbondSecure);
//GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey);
GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
2、我在启动配置后进入密钥连接事件,按照我的需求是如果连接密钥输入错误会断开连接。但是实际输入错误的密钥后,设备反而会快速连接。我在此处设置的代码是否有问题?
我在配对完成后的事件中添加了断开连接的处理事件。
/*********************************************************************
* @fn SimplePeripheral_processPairState
*
* @brief Process the new paring state.
*
* @return none
*/
static void SimplePeripheral_processPairState(spPairStateData_t *pPairData)
{
uint8_t state = pPairData->state;
uint8_t status = pPairData->status;
switch (state)
{
case GAPBOND_PAIRING_STATE_STARTED:
Display_printf(dispHandle, SP_ROW_CONNECTION, 0, "Pairing started");
break;
case GAPBOND_PAIRING_STATE_COMPLETE:
if (status == SUCCESS)
{
Display_printf(dispHandle, SP_ROW_CONNECTION, 0, "Pairing success");
}
else
{
//Disconnected
HCI_EXT_DisconnectImmedCmd();
Display_printf(dispHandle, SP_ROW_CONNECTION, 0, "Pairing fail: %d", status);
}
break;
case GAPBOND_PAIRING_STATE_ENCRYPTED:
if (status == SUCCESS)
{
Display_printf(dispHandle, SP_ROW_CONNECTION, 0, "Encryption success");
}
else
{
Display_printf(dispHandle, SP_ROW_CONNECTION, 0, "Encryption failed: %d", status);
//HCI_EXT_DisconnectImmedCmd();
}
break;
case GAPBOND_PAIRING_STATE_BOND_SAVED:
if (status == SUCCESS)
{
Display_printf(dispHandle, SP_ROW_CONNECTION, 0, "Bond save success");
}
else
{
//Display_printf(dispHandle, SP_ROW_CONNECTION, 0, "Bond save failed: %d", status);
//HCI_EXT_DisconnectImmedCmd();
}
break;
default:
break;
}
}