phy6222 配置pin码配对
pin码配对的配置
#define DEFAULT_PASSCODE 123456
// Default GAP pairing mode
//#define DEFAULT_PAIRING_MODE GAPBOND_PAIRING_MODE_INITIATE
#define DEFAULT_PAIRING_MODE GAPBOND_PAIRING_MODE_WAIT_FOR_REQ
// Default MITM mode (TRUE to require passcode or OOB when pairing)
// #define DEFAULT_MITM_MODE FALSE
#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_DISPLAY_ONLY
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_DEFAULT_PASSCODE, sizeof( uint32 ), &passkey );// 设置默认密码
GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof( uint8 ), &pairMode );// 设置配对模式
GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof( uint8 ), &mitm );// 是否需要pin码
GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof( uint8 ), &ioCap );// 设置输入方式,只有从机输入pin码
GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof( uint8 ), &bonding );// 是否需要绑定
phy绑定回调注册
实现密码回调函数
/*********************************************************************
@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 hidbdPasscodeEvtCB(uint8 *deviceAddr, uint16 connectionHandle, uint8 uiInputs, uint8 uiOutputs)
{
uint32 passkey = 0;
GAPBondMgr_GetParameter(GAPBOND_DEFAULT_PASSCODE, &passkey);
LOG("passkey:%d", passkey);
// LOG("connectionHandle:%d uiInputs:%d uiOutputs:%d DEFAULT_PASSCODE:%d", connectionHandle,uiInputs, uiOutputs, DEFAULT_PASSCODE);
GAPBondMgr_PasscodeRsp(connectionHandle, SUCCESS, passkey);
}
利用HidDev_Register(&hidKbdCfg, &hidKbdHidCBs);函数将回调函数注册到底层驱动;
注意问题
使用安卓手机配对设备的时候,需要输入完整的6位数,比如设置pin码位123则安卓手机系统连接的时候需要输入000123,而苹果手机则不需要直接输入123即可