大家好、
我对加密配对有两个问题。
1.在初始设置过程中,我已将配对后的选项设置为“假”,但在成功连接手机后,设备仍将自动绑定。 我设置的代码 如下。
// 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;
}
}
此致、
凯瑟琳