Part Number: CC2340R5
Tool/software:
Hi Forum,
I have implemented GAP Client Role in which i am trying to discover a char handles using char UUID using API "GATT_DiscCharsByUUID" and finding Handles. Using those Handle i am trying to read a char value using API "GATT_ReadCharValue()". the response i am getting 0x00, but actual char value is 0x02.
I tried with other client(nRF Connect) i tried connecting to Peripheral device and read same char value and i got correct response i.e. 0x02.
I am sure of "char Handle" value, since i've verified with sniffer.
uint8_t UUID[2] = {0xF0,0xFF};
void disc_services()
{
switch(Disc_state)
{
case MTU_EXCHANGE:
{
sprint("\nMTU Exchange");
uint8_t status;
attExchangeMTUReq_t req;
req.clientRxMTU = MAX_PDU_SIZE- L2CAP_HDR_SIZE;
status = GATT_ExchangeMTU(App_connHndl, &req, BLEAppUtil_getSelfEntity());
if(status == SUCCESS)
{
Disc_state = DISCOVER_PRIMARY_SERVICE;
}
else{
Disc_state = DISC_FAIL;
}
break;
}
case DISCOVER_PRIMARY_SERVICE:
{
sprint("\nDiscovery Primary Service");
uint8_t status;
status = GATT_DiscPrimaryServiceByUUID(App_connHndl,UUID, ATT_BT_UUID_SIZE, BLEAppUtil_getSelfEntity());
if( status == SUCCESS)
{
sprint("\nStatus:");print(&status,1);
Disc_state = STORE_PRIM_SERVICE_HNDLS;
}
else
{
Disc_state = DISC_FAIL;
}
break;
}
case STORE_PRIM_SERVICE_HNDLS:
{
sprint("\nStore Prim Service Hndls");
if(gattMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP)
{
startHndl = ATT_ATTR_HANDLE(gattMsg->msg.findByTypeValueRsp.pHandlesInfo,0);
endHndl = ATT_GRP_END_HANDLE(gattMsg->msg.findByTypeValueRsp.pHandlesInfo,0);
sprint("\nstart:");print(&startHndl,2);sprint(" | end:");print(&endHndl,2);
Disc_state = DISCOVER_SERVICE_CHAR;
BLEAppUtil_invokeFunctionNoData(disc_services);
}
break;
}
case DISCOVER_SERVICE_CHAR:
{
sprint("\nDiscover_Service_Char");
uint8_t status;
uint8_t serUUID[2] = {0xF2,0xFF};
attReadByTypeReq_t pReq;
pReq.startHandle = startHndl;
pReq.endHandle = endHndl;
pReq.type.len = ATT_BT_UUID_SIZE;
memcpy(pReq.type.uuid,serUUID,ATT_BT_UUID_SIZE);
status = GATT_DiscCharsByUUID(App_connHndl,&pReq,BLEAppUtil_getSelfEntity());
sprint("\nStatus:");print(&status,1);
if(status == SUCCESS)
{
Disc_state = STORE_SERVICE_HNDL;
}
break;
}
case STORE_SERVICE_HNDL:
{
sprint("\nSTORE_SERVICE_HNDL");
if(gattMsg->method == ATT_READ_BY_TYPE_RSP )
{
sprint("\nDataLen:");print(&gattMsg->msg.readByTypeRsp.dataLen,2);
sprint("\nnumPair:");print(&gattMsg->msg.readByTypeRsp.numPairs,1);
if( gattMsg->msg.readByTypeRsp.numPairs > 0)
{
uint16_t rspUUID;
for(uint8_t i=0; i < gattMsg->msg.readByTypeRsp.numPairs; i++)
{
uint8_t* p = gattMsg->msg.readByTypeRsp.pDataList + i*gattMsg->msg.readByTypeRsp.len;
rspUUID = BUILD_UINT16(p[5], p[6]);
if(rspUUID == 0xFFF2)
{
char_startHndl = BUILD_UINT16(p[3],p[4]);
char_endHndl = BUILD_UINT16(p[7],p[8]);
Disc_state = READ_CHAR_VAL;
sprint("\nDone...");sprint("start: ");print(&char_startHndl,2);sprint("EndHndl:");print(&char_endHndl,2);
BLEAppUtil_invokeFunctionNoData(disc_services);
}
}
}
else
sprint("\nNum Pairs are less");
}
break;
}
case READ_CHAR_VAL:
{
sprint("\nREAD_CHAR_VAL");
uint8_t status;
attReadReq_t pReq;
pReq.handle = char_startHndl;
sprint(" | Hndl:");print(&pReq.handle,2);
status = GATT_ReadCharValue(App_connHndl,&pReq,BLEAppUtil_getSelfEntity());
if(status == SUCCESS)
{
Disc_state = DISPLAY_CHAR_VAL;
}
else
{
sprint(" | status:");print(&status,1);
Disc_state = READ_CHAR_VAL;
BLEAppUtil_invokeFunctionNoData(disc_services);
}
break;
}
case DISPLAY_CHAR_VAL:
{
sprint("\nDISPLAY_CHAR_VAL");
sprint("\nMsg:");print(&gattMsg->msg.readRsp,2);
Disc_state = DISC_COMPLETE;
break;
}
Please let me know, why i am getting wrong response.
Regards
Vaibhav