This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: Simple Service Discovery 128bit UUID

Part Number: CC2640R2F

Hello,

I am trying to discover the simple service in a modified simple_central example after changing it to a 128bit UUID on the simple_peripheral side. I am having some trouble in this process, specifically with getting the handle of the service. Here is the code I have started modifying in the Gatt discovery function:

 if (discState == BLE_DISC_STATE_MTU)
  {
    // MTU size response received, discover simple service
    if (pMsg->method == ATT_EXCHANGE_MTU_RSP)
    {
        //Look at this and fix this later!!!!!!!!
      uint8_t uuid[ATT_UUID_SIZE] = {FANGRECEIVER_SERV_UUID};

      // Just in case we're using the default MTU size (23 octets)
      sprintf(displayBuff, "MTU Size: %d", ATT_MTU_SIZE);
      queueDisplayString(displayBuff);

      discState = BLE_DISC_STATE_SVC;

      // Discovery simple service
      VOID GATT_DiscPrimaryServiceByUUID(connHandle, uuid, ATT_UUID_SIZE,
                                         selfEntity);
    }
  }
  else if (discState == BLE_DISC_STATE_SVC)
  {
    // Service found, store handles
    if (pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
        pMsg->msg.findByTypeValueRsp.numInfo > 0)
    {
      svcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
      svcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
    }

    // If procedure complete
    if (((pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP) &&
         (pMsg->hdr.status == bleProcedureComplete))  ||
        (pMsg->method == ATT_ERROR_RSP))
    {
      if (svcStartHdl != 0)
      {
        attReadByTypeReq_t req;

        // Discover characteristic
        discState = BLE_DISC_STATE_CHAR;

        req.startHandle = svcStartHdl;
        req.endHandle = svcEndHdl;
        req.type.len = ATT_UUID_SIZE;
       // req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
       // req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID); //Make higher value to discover others?
       // req.type.uuid[] = { 0x00,  0x00,  0x00,  0x81,  0x03,  0x74,  0x19,  0x13,
        //0x54,  0xF1,  0xAD,  0xDE,  0xD1,  0xD1,  0xD1,  0xD1};
        req.type.uuid[0] = 0x00;
        req.type.uuid[1] = 0x00;
        req.type.uuid[2] = 0x00;
        req.type.uuid[3] = 0x81;
        req.type.uuid[4] = 0x03;
        req.type.uuid[5] = 0x74;
        req.type.uuid[6] = 0x19;
        req.type.uuid[7] = 0x13;
        req.type.uuid[8] = 0x54;
        req.type.uuid[9] = 0xF1;
        req.type.uuid[10] = 0xAD;
        req.type.uuid[11] = 0xDE;
        req.type.uuid[12] = 0xD1;
        req.type.uuid[13] = 0xD1;
        req.type.uuid[14] = 0xD1;
        req.type.uuid[15] = 0xD1;

        VOID GATT_ReadUsingCharUUID(connHandle, &req, selfEntity);
      }
    }
  }
  else if (discState == BLE_DISC_STATE_CHAR)
  {
    // Characteristic found, store handle
    if ((pMsg->method == ATT_READ_BY_TYPE_RSP) &&
        (pMsg->msg.readByTypeRsp.numPairs > 0))
    {
      charHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
                             pMsg->msg.readByTypeRsp.pDataList[1]);

      queueDisplayString("Simple Svc Found");
      procedureInProgress = FALSE;
    }

    discState = BLE_DISC_STATE_IDLE;
  }

It seems to successfully find the primary service uuid which is 128 bit, however, when it moves on to the simple service discovery, it does not seem to be successful and move on to the characteristic discovery. I think I need to change the lines:

svcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
svcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);

I am not sure what these need to be changed to or if there is anything else I am missing here. I can't seem to find any other posts about this or examples on 128bit service/characteristic discovery. Any help or pointer on this would be greatly appreciated.

Thanks,

Josh

 

  • Also, forgot to mention, it is not getting past the If procedure complete if statement. When single stepping, the pMsg->method is 7 which is fine, but the pMsg->hdr.status is reading as 0x14, not the required 0x1A. Additionally, both svcStartHdl and svcEndHdl are reading as 0.
  • Hi Josh,

    I don't understand the situation. Are you saying GATT_DiscPrimaryServiceByUUID() works as intended (returns success, then ATT_FIND_BY_TYPE_VALUE_RSP events)?

    And then GATT_ReadUsingCharUUID() does not return success? (Or you only get ATT_ERROR_RSP?)

    GATT_ReadUsingCharUUID() is meant for reading a characteristic, but in simple central it's also used to discover the characteristic (since both handle and value are returned with the ATT_READ_BY_TYPE_RSP event). However if the characteristic you are trying to discover does not have the Read property, you won't be able to use this API to discover it. You can use GATT_DiscCharsByUUID() instead.
  • Hello Marie,

    Thank you for the quick reply. To clarify, the situation, the primary service discovery is working fine with the 128bit uuid service id. However, the characteristic discovery with 128bit uuid characteristic does not work.

    I have reverted back to using the 16bit uuid characteristic (which works fine) for other testing, and am now testing out discovering multiple characteristics in the service. I did try the GATT_DiscCharsByUUID() in place of the GATT_ReadUsingCharUUID(), but it does not work when I try and use the handle later in a GATT_WriteCharValue() function (Returns "Write Error 3" on console). Looking at the handle the DiscChar sets charHdl to 29 where as the ReadUsingChar function that works sets it to 30. Not sure why this is.

    I have also tried using the GATT_DiscAllChars() function, which does seem to find all five characteristics, but reading their handles does not seem to work. I am referencing this post here for this: e2e.ti.com/.../514007

    Basically, I am trying to make several custom 128bit characteristics in my service and discover them to read/write to on the central side. I can not find much information on this other than a few older posts that are not too helpful. Is there any documentation related to this regarding 128bit uuid char discovery and multiple char discovery?

    I guess the first thing I would like to figure out is the 128bit characteristic discovery. Once that is done I can move on to the multiple characteristic discovery process.

    I really appreciated the help.
    Thanks,
    Josh
  • Hi Josh,

    When you say: Does not work, can you be more specific? Does the API call return a failure status? Are you getting ATT_ERROR_RSP events?

    The attribute table can change when you re-program the device (so the handle can change from 29 to 30).

    Can you try using BTool + host test to discover all services and see what the attribute table looks like?

    GATT_DiscCharsByUUID() will also return ATT_READ_BY_TYPE_RSP events if successfull, so please make sure your application is catching these events.
  • Hello Marie,

    Thank you again for the quick reply.

    The API returns success for both the GATT_DiscCharsByUUID() and also the GATT_DiscAllChars() function. I don't believe the attribute table is changing. When the handle of the first characteristic is set to 29, I can no longer write that characteristic later in my code using that handle. However, if I change the handle manually to 30 in debugg mode, it can write the characteristic value fine using the handle. It seems to remain as 30 in my tests. Also, the attribute table is the exact same as the original simple_peripheral example. The only thing that has changed there is the containing service is now a 128bit UUID.

    I think something is wrong with how the readByTypeRsp data is being broken down when received. I have updated my code to the following to discover all 5 characteristics (all 16bit atm)

      if (discState == BLE_DISC_STATE_MTU)
      {
        // MTU size response received, discover simple service
        if (pMsg->method == ATT_EXCHANGE_MTU_RSP)
        {
          uint8_t uuid[ATT_UUID_SIZE] = {FANGRECEIVER_SERV_UUID};
    
          // Just in case we're using the default MTU size (23 octets)
          sprintf(displayBuff, "MTU Size: %d", ATT_MTU_SIZE);
          queueDisplayString(displayBuff);
    
          discState = BLE_DISC_STATE_SVC;
    
          // Discovery simple service
          VOID GATT_DiscPrimaryServiceByUUID(connHandle, uuid, ATT_UUID_SIZE,
                                             selfEntity);
        }
      }
      else if (discState == BLE_DISC_STATE_SVC)
      {
        // Service found, store handles
        if (pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
            pMsg->msg.findByTypeValueRsp.numInfo > 0)
        {
          svcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
          svcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
        }
    
        // If procedure complete
        if (((pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP) &&
             (pMsg->hdr.status == bleProcedureComplete))  ||
            (pMsg->method == ATT_ERROR_RSP))
        {
          if (svcStartHdl != 0)
          {
            attReadByTypeReq_t req;
    
            discState = BLE_DISC_STATE_CHAR;
    
            //Discover All Characteristics
            status =  GATT_DiscAllChars(connHandle, svcStartHdl, svcEndHdl, selfEntity);
    
    
          }
        }
      }
      else if (discState == BLE_DISC_STATE_CHAR)
      {
        // Characteristic found, store handle
        if ((pMsg->method == ATT_READ_BY_TYPE_RSP) &&
            (pMsg->msg.readByTypeRsp.numPairs > 0))
        {
    
                char1Hdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
                                        pMsg->msg.readByTypeRsp.pDataList[1]);
    
    
          queueDisplayString("Simple Svc Found");
    
          procedureInProgress = FALSE;
        }
    
        discState = BLE_DISC_STATE_IDLE;
      }

    After the GATT_DiscAllChars() is called, the application gets a message of type ATT_READ_BY_TYPE_RSP. When I debug on the line where I set the value of char1Hdl for instance, the pMsg->msg.readByTypeRsp has numPairs = 5, len = 7, pDataList = 29, and dataLen = 31621. So a few things here, first, I can see that is has discovered 5 characteristics, however, they are not in the pDataList? Shouldn't they be? Also, I am still not sure why the handle is 29 and not 30 in this case. 

    I believe the problem is with this. I am also confused about how in this post:  

    They are using the findInfoRsp structure after calling the GATT_DiscAllChars(). I am not sure how this is possible. 

    Thanks again,

    Josh 

  • Hello,
    I manged to figure my problem out over the weekend. It turned out the discover all function was returing the required information in the message and I just wasn't seeing it. I was able to sort this info and pull the required handles for each uuid. I was also able to get the 128bit uuid to work with some custom handlers.
    Thank you for your help again,
    Josh