// Default MITM mode (TRUE to require passcode or OOB when pairing) 设置开启
#define DEFAULT_MITM_MODE TRUE
// Default bonding mode, TRUE to bond
#define DEFAULT_BONDING_MODE TRUE
// Default GAP bonding I/O capabilities 启动键盘输入密码功能
#define DEFAULT_IO_CAPABILITIES GAPBOND_IO_CAP_KEYBOARD_ONLY
// Setup the GAP Bond Manager 作用代码
{
uint32 passkey = DEFAULT_PASSCODE;
uint8 pairMode = DEFAULT_PAIRING_MODE;
uint8 mitm = DEFAULT_MITM_MODE;
uint8 ioCap = DEFAULT_IO_CAPABILITIES;
uint8 bonding = DEFAULT_BONDING_MODE;
GAPBondMgr_SetParameter( GAPBOND_PERI_DEFAULT_PASSCODE, sizeof( uint32 ), &passkey );
GAPBondMgr_SetParameter( GAPBOND_PERI_PAIRING_MODE, sizeof( uint8 ), &pairMode );
GAPBondMgr_SetParameter( GAPBOND_PERI_MITM_PROTECTION, sizeof( uint8 ), &mitm );
GAPBondMgr_SetParameter( GAPBOND_PERI_IO_CAPABILITIES, sizeof( uint8 ), &ioCap );
GAPBondMgr_SetParameter( GAPBOND_PERI_BONDING_ENABLED, sizeof( uint8 ), &bonding );
}
设备被连接后,进入该回调函数,启动密码输入任务,等待输入密码
/*********************************************************************
* @fn hidDevPasscodeCB
*
* @brief Passcode callback.
*
* @param deviceAddr - address of device to pair with, and could be either public or random.
* @param connectionHandle - connection handle
* @param uiInputs - pairing User Interface Inputs - Ask user to input passcode
* @param uiOutputs - pairing User Interface Outputs - Display passcode
*
* @return none
*/
static void hidDevPasscodeCB( uint8 *deviceAddr, uint16 connectionHandle,
uint8 uiInputs, uint8 uiOutputs )
{
uint32 passkey =0;
if ( pHidDevCB && pHidDevCB->passcodeCB )
{
// execute HID app passcode callback
(*pHidDevCB->passcodeCB)( deviceAddr, connectionHandle, uiInputs, uiOutputs );
}
else
{
GAPBondMgr_GetParameter( GAPBOND_PERI_DEFAULT_PASSCODE, &passkey );
tmos_start_task(hidEmuTaskId,PASSKEY_EVT,400); //启动输入密码的任务
// GAPBondMgr_PasscodeRsp( connectionHandle, SUCCESS, passkey );
}
// Send passcode response
}
密码是在串口中断里面接收的(当然这个只是操作例子,不限制输入方式)
if ( events & PASSKEY_EVT )
{
uint32 passkey =0;
uint8 i;
if((Rcvlen==8))
{
for(i=2;i<8;i++) //密码是10进制数输入,需要进制进制转换
{
passkey=10*passkey;
passkey+=(RxBuff[i]-0x30);
PRINT(" %d",RxBuff[i]);
}
PRINT(" %d",passkey);
Rcvlen =0;
GAPBondMgr_PasscodeRsp( hidEmuConnHandle, SUCCESS, passkey ); //输入密码
}
else {
tmos_start_task(hidEmuTaskId,PASSKEY_EVT,400);//如果没有接收到密码,重新开启任务
}
return ( events ^ PASSKEY_EVT );
}