Part Number: CC2640R2F
Other Parts Discussed in Thread: BLE-STACK, CC2640
Tool/software: Code Composer Studio
Hi all,
I am trying to learn BLE stack with CC2640R2F. I took simple_peripheral example as a starting point. My task init function looks like this:
static void App_init( void ) {
ICall_registerApp(&selfEntity, &syncEvent);
Queue_construct(&appMsgQueue, NULL);
appMsgQueueHandle = Queue_handle(&appMsgQueue);
Util_constructClock(&clkPeriodic, App_clockHandler, 1000, 0, false, 0);
GAP_SetParamValue(GAP_PARAM_LINK_UPDATE_DECISION, GAP_UPDATE_REQ_ACCEPT_ALL);
GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, appDeviceName);
GASS_AddService();
GGS_AddService(GATT_ALL_SERVICES);
GATTServApp_AddService(GATT_ALL_SERVICES);
DevInfo_AddService();
BAT_AddService();
GAP_RegisterForMsgs(selfEntity);
GATT_RegisterForMsgs(selfEntity);
GATT_InitClient();
GAP_DeviceInit(GAP_PROFILE_PERIPHERAL, selfEntity, ADDRMODE_PUBLIC, NULL);
}
I've added my custom battery service (which works fine), but when I am connecting to my board with android with BLE scanning app, I see that GENERIC ACCESS properties are write only (see screenshot).
I've tried to manually set the permissions:
uint8 devNamePermission = GATT_PERMIT_READ; GGS_SetParameter(GGS_W_PERMIT_DEVICE_NAME_ATT, sizeof(uint8_t), &devNamePermission); GGS_SetParameter(GGS_W_PERMIT_APPEARANCE_ATT, sizeof(uint8_t), &devNamePermission);
It doesn't work. Also I've even tried to write my own generic access profile:
#include "icall_ble_api.h"
static uint8 devNameProps = GATT_PROP_READ;
static uint8 appearanceProps = GATT_PROP_READ;
static CONST gattAttrType_t gapService = { ATT_BT_UUID_SIZE, gapServiceUUID };
static uint8_t devName[GAP_DEVICE_NAME_LEN] = "TestDev";
static uint8_t appearance[] = {0};
static gattAttribute_t gapAttrTbl[] =
{
// Device Information Service
{
{ ATT_BT_UUID_SIZE, gapServiceUUID }, /* type */
GATT_PERMIT_READ, /* permissions */
0, /* handle */
(uint8 *)&gapService /* pValue */
},
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&devNameProps
},
// Dev name value
{
{ ATT_BT_UUID_SIZE, deviceNameUUID },
GATT_PERMIT_READ,
0,
(uint8 *) devName
},
// Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&appearanceProps
},
// Appearance value
{
{ ATT_BT_UUID_SIZE, appearanceUUID },
GATT_PERMIT_READ,
0,
(uint8 *) &appearance
},
};
static bStatus_t GACC_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
uint8 *pValue, uint16 *pLen, uint16 offset,
uint16 maxLen, uint8 method );
CONST gattServiceCBs_t gapCBs = {
GACC_ReadAttrCB, // Read callback function pointer
NULL, // Write callback function pointer
NULL // Authorization callback function pointer
};
bStatus_t GASS_AddService( void ) {
return GATTServApp_RegisterService( gapAttrTbl, GATT_NUM_ATTRS( gapAttrTbl ), GATT_MAX_ENCRYPT_KEY_SIZE, &gapCBs );
}
static bStatus_t GACC_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
uint8 *pValue, uint16 *pLen, uint16 offset,
uint16 maxLen, uint8 method ) {
bStatus_t status = SUCCESS;
if ( offset > 0 ) { return ( ATT_ERR_ATTR_NOT_LONG ); }
if ( pAttr->type.len == ATT_BT_UUID_SIZE ) {
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch ( uuid ) {
case DEVICE_NAME_UUID:
*pLen = 6;
memcpy( pValue, pAttr->pValue, *pLen );
break;
case APPEARANCE_UUID:
*pLen = 1;
pValue[0] = *pAttr->pValue;
break;
default:
*pLen = 0;
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
} else {
*pLen = 0;
status = ATT_ERR_INVALID_HANDLE;
}
return ( status );
}
It doesn't work either. The function GATTServApp_RegisterService returns 2 (invalid arg).
I compiled my project with two versions of compiler (16.9.4 and 20.2.1).
I was trying to load different examples (project zero and simple_peripheral with minimal changes due to custom board).
Please tell me where is the problem and how to solve it. And why can't I create my own generic access profile.
Thank you!
