微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > CC2540/2541 SimpleBLEPeripheral 里面设置为GATT_PERMIT_AUTHEN_READ的char5怎么才能读取?

CC2540/2541 SimpleBLEPeripheral 里面设置为GATT_PERMIT_AUTHEN_READ的char5怎么才能读取?

时间:10-02 整理:3721RD 点击:

1、请问SimpleBLEPeripheral 例子里面,char5被设置成GATT_PERMIT_AUTHEN_READ,那么我应该怎么读取它呢?

2、在SimpleBLEPeripheral 例子里面有个读属性的回调函数simpleProfile_ReadAttrCB.

static uint8 simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )
{
bStatus_t status = SUCCESS;

// If attribute permissions require authorization to read, return error
if ( gattPermitAuthorRead( pAttr->permissions ) )
{
// Insufficient authorization
return ( ATT_ERR_INSUFFICIENT_AUTHOR );
}

// Make sure it's not a blob operation (no attributes in the profile are long)
if ( offset > 0 )
{
return ( ATT_ERR_ATTR_NOT_LONG );
}

if ( pAttr->type.len == ATT_BT_UUID_SIZE )
{
// 16-bit UUID
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch ( uuid )
{
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
// gattserverapp handles those reads

// characteristics 1 and 2 have read permissions
// characteritisc 3 does not have read permissions; therefore it is not
// included here
// characteristic 4 does not have read permissions, but because it
// can be sent as a notification, it is included here
case SIMPLEPROFILE_CHAR1_UUID:
case SIMPLEPROFILE_CHAR2_UUID:
case SIMPLEPROFILE_CHAR4_UUID:
*pLen = 1;
pValue[0] = *pAttr->pValue;
break;

case SIMPLEPROFILE_CHAR5_UUID:
*pLen = SIMPLEPROFILE_CHAR5_LEN;
VOID osal_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
break;

default:
// Should never get here! (characteristics 3 and 4 do not have read permissions)
*pLen = 0;
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
}
else
{
// 128-bit UUID
*pLen = 0;
status = ATT_ERR_INVALID_HANDLE;
}

return ( status );
}

当已经得到鉴定后,读char5时会执行上面的回调函数吗?如果会的话,当执行到红色部分时函数同样会返回ATT_ERR_INSUFFICIENT_AUTHOR??这样还是没法读取char5??

hi edgar,

建议你打开鉴权, 如果master没有主动发送鉴权请求, 可以发slave request来做.

可以把你的连接的抓包过程贴出来看一下吗?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top