CC254x pairing and GATT authen read
我想让BLE设备与iphone连接使用时,需要配对,并且对其中一个characteristic实现鉴权读(GATT_PERMIT_AUTHEN_READ)。即需要在iphone连接时和读取characteristic时,都配对输密码。下面是我的步骤和结果
1. 我在程序中GAP Bond Manger配置如下:
// Setup the GAP Bond Manager
{
uint32 passkey = 0; // passkey "000000"
uint8 pairMode = GAPBOND_PAIRING_MODE_INITIATE;
uint8 mitm = TRUE;
uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_YES_NO;
uint8 bonding = FALSE;
GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey );
GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode );
GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm );
GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap );
GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding );
}
2.设置characteristic的权限为GATT_PERMIT_AUTHEN_READ,并且在xxxProfile_ReadAttrCB的读特征值的回调函数中加入下面一段代码
if ( gattPermitAuthenRead( pAttr->permissions ) )
{
// Insufficient authorization
return ( ATT_ERR_INSUFFICIENT_AUTHOR );
}
3.结果是:连接时能弹出要求配对输密码的界面,输入正确密码后,正常连接;但是,读取设置为GATT_PERMIT_AUTHEN_READ的特征值时,总是不断弹出要求配对输密码的界面,输入正确的密码后,还是不断弹出,根本读不到数据。请问一下这是这么回事呀?要怎样改才能输入正确密码一次就能读到数据?
// If attribute permissions require authorization to read, return error
if ( gattPermitAuthorRead( pAttr->permissions ) )
{
// Insufficient authorization
return ( ATT_ERR_INSUFFICIENT_AUTHOR );
}