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.

CC2340R5: CC2340R5 - Remove characteristics and service

Part Number: CC2340R5


Tool/software:

Good Morning,

thank you for replying to my previous post

This is a follow-up to my previous topic which consists of removing the following characteristics and  service :

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1463056/cc2340r5-cc2340r5---remove-characteristic-from-generic-access/5619460#5619460

we concluded that this was possible by modifying the sdk with gatt_uuid.c and gatt_uuid.h files, after resuming work, these files do not seem to modify the services and characteristic.

I've seen a lot of topics with the same problem on the forum. And answers that said it was impossible because it was part of a pre-compiled code that could not be modified.

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1346107/cc2340r5-how-to-change-generic-access-attribute-s-characteristic-properties

I'm a bit lost and I absolutely must remove them. Is there a solution and what steps do I need to take? Is there an api that lets me modify all this?

thanks in advance,

Best Regards,

Yohan

  • Hello Yohan,

    Thank you for reaching out! I will look into this and get back to you as soon as possible

    Best Regards,

    Tarek

  • Hello Yohan,

    Thank you for your patience! Upon looking further into the Bluetooth Core Specification (Specifically Version 5.4 | Vol 3, Part C), I was able to conclude the following regarding the characteristics mentioned in your previous E2E thread:

    • Peripheral Preferred Connection Parameters:
      In a central role, this characteristic is excluded. In a peripheral role, this characteristic is optional.
    • Central Address Resolution:
      In a central role, this characteristic is mandatory if Link Layer privacy is enabled, otherwise it is excluded. In a peripheral role, this characteristic is optional if Link Layer privacy is enabled, otherwise it is excluded.
    • Resolvable Private Address Only:
      In both peripheral and central roles, this characteristic is optional if Link Layer privacy is enabled, otherwise it is excluded.

    Since you mentioned that you're following a certain specification and need these characteristics removed, you will need to disable Link Layer privacy, this will exclude all 3 of the characteristics mentioned above. Below, I've included an example on how to do this for a peripheral role device:

    1. Go to the app_peripheral.c file inside the app folder in the project.
    2. Add the following event handler near the other event handlers in the project:
      BLEAppUtil_EventHandler_t peripheralHCIHandler =
      {
          .handlerType = BLEAPPUTIL_HCI_GAP_TYPE, // Handler type.
          .pEventHandler = Peripheral_HCIEventHandler, // Function to handle events.
          .eventMask = BLEAPPUTIL_HCI_COMMAND_COMPLETE_EVENT_CODE // HCI events to subscribe to.
                       | BLEAPPUTIL_HCI_VE_EVENT_CODE,
      }; 


    3. Upon the occurrence of the event mentioned above, the code included below will read the supported features, then proceed to disable the link layer :
      void Peripheral_HCIEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
      {
          switch (event)
          {
              case BLEAPPUTIL_HCI_COMMAND_COMPLETE_EVENT_CODE:
              {
                  hciEvt_CmdComplete_t* command_complete = (hciEvt_CmdComplete_t*) pMsgData;
      
                  switch (command_complete->cmdOpcode)
                  {
                      case HCI_LE_READ_LOCAL_SUPPORTED_FEATURES:
                      {
                          uint8_t status = command_complete->pReturnParam[0];
      
                          if (status == SUCCESS)
                          {
                              // Get current feature set from received event (bytes 1-9
                              // of the returned data
                              uint8_t featSet[8];
      
                              memcpy(featSet, &(command_complete->pReturnParam[1]), 8 );
      
                              // Clear bit 7 of byte 1 of feature set to disable LL
                              // the Channel Selection Algorithm 2 feature
                              CLR_FEATURE_FLAG(featSet[0], LL_FEATURE_PRIVACY);
      
                              // Update controller with modified features
                              HCI_EXT_SetLocalSupportedFeaturesCmd( featSet );
                          }
      
                          break;
                      }
      
                  }
                  break;
              }
      
              case BLEAPPUTIL_HCI_VE_EVENT_CODE:
              {
                  break;
              }
              default: break;
          }
      } 


    4. Finally, scroll to the end of the project and add the following function to the end of the peripheral_start() function, right before the last return(status); function:
      HCI_LE_ReadLocalSupportedFeaturesCmd();

    This should successfully disable the Link Layer privacy, which will cause all the unwanted characteristics to be excluded.

    I hope this helps!

    Best Regards,

    Tarek

  • Hello,

    Thank you Tarek for your reactive answer.


    Unfortunately the problem seems to persist, I took the liberty of adding the following function BLEAppUtil_registerEventHandler(&peripheralHCIHandler); to register the event in  Peripheral_start().


    bStatus_t Peripheral_start()
    {
      bStatus_t status = SUCCESS;
    
      status = BLEAppUtil_registerEventHandler(&peripheralConnHandler);
      if (status != SUCCESS)
      {
        // Return status value
        return (status);
      }
    
      status = BLEAppUtil_registerEventHandler(&peripheralAdvHandler);
      if (status != SUCCESS)
      {
        return (status);
      }
    
      status = BLEAppUtil_initAdvSet(&peripheralAdvHandle_1, &advSetInitParamsSet_1);
      if (status != SUCCESS)
      {
        // Return status value
        return (status);
      }
    
      // Note that the structure is used to register the event handler.
      status = BLEAppUtil_registerEventHandler(&peripheralHCIHandler);
      if (status != SUCCESS)
      {
        // Return status value
        return (status);
      }
    
      HCI_LE_ReadLocalSupportedFeaturesCmd();
    
      // Return status value
      return (status);
    }

    With the debugger, I see we enter in the event callback "Peripheral_HCIEventHandler" and all the function return a success but the characteristic are still present.

    Best Regards,

    Yohan

  • Hello Yohan,

    Deactivating the Link Layer privacy should automatically exclude the characteristics, I've ran the code on my side and it worked. Can you please provide a packet sniffer log of this?

    Best Regards,

    Tarek

  • Good Afternoon Tarek,

    I have implemented the modification on basic_ble_LP_EM_CC2340R5_freertos_ticlang project  to be sure the problem isn't link to my project and I have the same result.


    I must have misunderstood something about the modification to be made to app_peripheral.c

    here my app_peripheral.c:

    /******************************************************************************
    
    @file  app_peripheral.c
    
    @brief This example file demonstrates how to activate the peripheral role with
    the help of BLEAppUtil APIs.
    
    Two structures are used for event handling, one for connection events and one
    for advertising events.
    In each, eventMask is used to specify the events that will be received
    and handled.
    In addition, fill the BLEAppUtil_AdvInit_t structure with variables generated
    by the Sysconfig.
    
    In the events handler functions, write what actions are done after each event.
    In this example, after a connection is made, activation is performed for
    re-advertising up to the maximum connections.
    
    In the Peripheral_start() function at the bottom of the file, registration,
    initialization and activation are done using the BLEAppUtil API functions,
    using the structures defined in the file.
    
    More details on the functions and structures can be seen next to the usage.
    
    Group: WCS, BTS
    Target Device: cc23xx
    
    ******************************************************************************
    
     Copyright (c) 2022-2024, Texas Instruments Incorporated
     All rights reserved.
    
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions
     are met:
    
     *  Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
    
     *  Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    
     *  Neither the name of Texas Instruments Incorporated nor the names of
        its contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.
    
     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    ******************************************************************************
    
    
    *****************************************************************************/
    
    #if defined( HOST_CONFIG ) && ( HOST_CONFIG & ( PERIPHERAL_CFG ) )
    
    //*****************************************************************************
    //! Includes
    //*****************************************************************************
    #include "ti_ble_config.h"
    #include <ti/bleapp/ble_app_util/inc/bleapputil_api.h>
    #include <ti/bleapp/menu_module/menu_module.h>
    #include <app_main.h>
    
    //*****************************************************************************
    //! Prototypes
    //*****************************************************************************
    void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData);
    void Peripheral_GAPConnEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData);
    void Peripheral_HCIEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData);
    
    //*****************************************************************************
    //! Globals
    //*****************************************************************************
    
    BLEAppUtil_EventHandler_t peripheralConnHandler =
    {
        .handlerType    = BLEAPPUTIL_GAP_CONN_TYPE,
        .pEventHandler  = Peripheral_GAPConnEventHandler,
        .eventMask      = BLEAPPUTIL_LINK_ESTABLISHED_EVENT |
                          BLEAPPUTIL_LINK_PARAM_UPDATE_REQ_EVENT |
                          BLEAPPUTIL_LINK_TERMINATED_EVENT,
    };
    
    BLEAppUtil_EventHandler_t peripheralAdvHandler =
    {
        .handlerType    = BLEAPPUTIL_GAP_ADV_TYPE,
        .pEventHandler  = Peripheral_AdvEventHandler,
        .eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                          BLEAPPUTIL_ADV_END_AFTER_DISABLE
    };
    BLEAppUtil_EventHandler_t peripheralHCIHandler =
    {
        .handlerType = BLEAPPUTIL_HCI_GAP_TYPE, // Handler type.
        .pEventHandler = Peripheral_HCIEventHandler, // Function to handle events.
        .eventMask = BLEAPPUTIL_HCI_COMMAND_COMPLETE_EVENT_CODE // HCI events to subscribe to.
                     | BLEAPPUTIL_HCI_VE_EVENT_CODE,
    };
    //! Store handle needed for each advertise set
    uint8 peripheralAdvHandle_1;
    
    //! Advertise param, needed for each advertise set, Generate by Sysconfig
    const BLEAppUtil_AdvInit_t advSetInitParamsSet_1 =
    {
        /* Advertise data and length */
        .advDataLen        = sizeof(advData1),
        .advData           = advData1,
    
        /* Scan respond data and length */
        .scanRespDataLen   = sizeof(scanResData1),
        .scanRespData      = scanResData1,
    
        .advParam          = &advParams1
    };
    
    const BLEAppUtil_AdvStart_t advSetStartParamsSet_1 =
    {
        /* Use the maximum possible value. This is the spec-defined maximum for */
        /* directed advertising and infinite advertising for all other types */
        .enableOptions         = GAP_ADV_ENABLE_OPTIONS_USE_MAX,
        .durationOrMaxEvents   = 0
    };
    
    //*****************************************************************************
    //! Functions
    //*****************************************************************************
    void Peripheral_HCIEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch (event)
        {
            case BLEAPPUTIL_HCI_COMMAND_COMPLETE_EVENT_CODE:
            {
                hciEvt_CmdComplete_t* command_complete = (hciEvt_CmdComplete_t*) pMsgData;
    
                switch (command_complete->cmdOpcode)
                {
                    case HCI_LE_READ_LOCAL_SUPPORTED_FEATURES:
                    {
                        uint8_t status = command_complete->pReturnParam[0];
    
                        if (status == SUCCESS)
                        {
                            // Get current feature set from received event (bytes 1-9
                            // of the returned data
                            uint8_t featSet[8];
    
                            memcpy(featSet, &(command_complete->pReturnParam[1]), 8 );
    
                            // Clear bit 7 of byte 1 of feature set to disable LL
                            // the Channel Selection Algorithm 2 feature
                            CLR_FEATURE_FLAG(featSet[0], LL_FEATURE_PRIVACY);
    
                            // Update controller with modified features
                            uint8_t status = HCI_EXT_SetLocalSupportedFeaturesCmd( featSet );
                            if (status != SUCCESS)
                            {
                              break;
                            }
                        }
    
                        break;
                    }
    
                }
                break;
            }
    
            case BLEAPPUTIL_HCI_VE_EVENT_CODE:
            {
                break;
            }
            default: break;
        }
    }
    /*********************************************************************
     * @fn      Peripheral_AdvEventHandler
     *
     * @brief   The purpose of this function is to handle advertise events
     *          that rise from the GAP and were registered in
     *          @ref BLEAppUtil_registerEventHandler
     *
     * @param   event - message event.
     * @param   pMsgData - pointer to message data.
     *
     * @return  none
     */
    void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch(event)
        {
            case BLEAPPUTIL_ADV_START_AFTER_ENABLE:
            {
                MenuModule_printf(APP_MENU_ADV_EVENT, 0, "Adv status: Started - handle: "
                                  MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
                                  ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);
                break;
            }
    
            case BLEAPPUTIL_ADV_END_AFTER_DISABLE:
            {
                MenuModule_printf(APP_MENU_ADV_EVENT, 0, "Adv status: Ended - handle: "
                                  MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
                                  ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);
                break;
            }
    
            default:
            {
                break;
            }
        }
    }
    
    /*********************************************************************
     * @fn      Peripheral_GAPConnEventHandler
     *
     * @brief   The purpose of this function is to handle connection related
     *          events that rise from the GAP and were registered in
     *          @ref BLEAppUtil_registerEventHandler
     *
     * @param   event - message event.
     * @param   pMsgData - pointer to message data.
     *
     * @return  none
     */
    void Peripheral_GAPConnEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch(event)
        {
            case BLEAPPUTIL_LINK_ESTABLISHED_EVENT:
            {
                /* Check if we reach the maximum allowed number of connections */
                if(linkDB_NumActive() < linkDB_NumConns())
                {
                    /* Start advertising since there is room for more connections */
                    BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
                }
                else
                {
                    /* Stop advertising since there is no room for more connections */
                    BLEAppUtil_advStop(peripheralAdvHandle_1);
                }
                break;
            }
    
            case BLEAPPUTIL_LINK_TERMINATED_EVENT:
            {
                BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
                break;
            }
    
            default:
            {
                break;
            }
        }
    }
    
    /*********************************************************************
     * @fn      Peripheral_start
     *
     * @brief   This function is called after stack initialization,
     *          the purpose of this function is to initialize and
     *          register the specific events handlers of the peripheral
     *          application module
     *
     * @return  SUCCESS, errorInfo
     */
    bStatus_t Peripheral_start()
    {
      bStatus_t status = SUCCESS;
    
      status = BLEAppUtil_registerEventHandler(&peripheralConnHandler);
      if (status != SUCCESS)
      {
        // Return status value
        return (status);
      }
    
      status = BLEAppUtil_registerEventHandler(&peripheralAdvHandler);
      if (status != SUCCESS)
      {
        return (status);
      }
    
      status = BLEAppUtil_initAdvSet(&peripheralAdvHandle_1, &advSetInitParamsSet_1);
      if (status != SUCCESS)
      {
        // Return status value
        return (status);
      }
    
      // Note that the structure is used to register the event handler.
      status = BLEAppUtil_registerEventHandler(&peripheralHCIHandler);
      if (status != SUCCESS)
      {
        // Return status value
        return (status);
      }
    
      HCI_LE_ReadLocalSupportedFeaturesCmd();
    
      status = BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
      if(status != SUCCESS)
      {
          // Return status value
          return(status);
      }
    
      // Return status value
      return (status);
    }
    
    #endif // ( HOST_CONFIG & ( PERIPHERAL_CFG ) )
    


    Did i miss something?

    Really Thank you for your support Tarek !

    Best Regards,

    Yohan

  • Hello Yohan,

    I'm looking into other reasons for this to be happening. In the mean time, can you move the HCI_LE_ReadLocalSupportedFeaturesCmd() function below the BLEAppUtill_advStart function? That might be causing an issue.

    Best Regards,

    Tarek

  • Hello Tarek,

    No change by placing it below advertising activation.

    Best Regards,

    Yohan

  • Hello Yohan,

    If you can, please provide a packet sniffer log (using an ellisys preferably or using wireshark) so I can see whether the disable Link Layer privacy packet is being transmitted or not. This will be really beneficial in pinpointing the problem, as I haven't been able to replicate this on my system.

    Best Regards,

    Tarek

  • Hello Tarek,

    Here a screenshot of the packet log:

    I have the .pcapng for more details but i don't know how to send it.

    The LL privacy seems well disabled.

    Best regards,

    Yohan,

  • Hello Yohan,

    Thank you for providing the screenshot! If the LL privacy is being disabled, according to the spec, the characteristics you need removed will be excluded. I suspect that the app you are using to check the characteristics might be giving you inaccurate or old data. Could you possibly test a different app and confirm that you are still seeing this? Also, could you make sure the board is not bonded to the phone. If it is, make sure to delete the device from the bluetooth devices list and retest.

    Best Regards,

    Tarek

  • Hello Tarek,

    I've tested it with different phones, dongle/computer and the problem persists.Could the problem be linked to the SDK? Or to the sample project?

    CC2340R5
    SDK: simplelink_lowpower_f3_sdk_8_10_01_02

    Exemple Project:  basic_ble_LP_EM_CC2340R5_freertos_ticlang 

    Best Regards,

    Yohan

  • Hello Yohan,

    Could you try moving to the newest SDK(8.40) and let me know if the problem persists. We will hopefully get this resolved soon!

    Best Regards,

    Tarek

  • Hello Tarek,

    thank you, I wil try to migrate my project. This is a known problem that has been corrected in the latest SDK?

    Best Regards,


    Yohan

  • Good afternoon Tarek,


    I tested it with the latest skd (simplelink_lowpower_f3_sdk_8_40_02_01) and observed the same phenomenon. To simplify the task, I didn't migrate my project but just imported the new basic ble project (simplelink_lowpower_f3_sdk_8_40_02_01) and deactivated LL privacy. LL Privacy is deactivated, but the characteristics remain.


    my tool chain is as follows:

    Products option:

    code composer: 12.7.1.00001

    Cortex_M0P: Flash loader: CC23xx_CC27xx_FLASH_LIBRARY_VERSION 3.19.0.12


    Maybe there's something else to do once you've disabled LL privacy so that lstack ble removes it?

    Best regards,

    Yohan

  • Hello Yohan,

    I haven't been able to replicate the issue. It'll be very helpful if you provided the full packet sniffer log, either by posting it here or having the FAE in charge of your account send it to me via email.

    Also, could you import a default basic_ble project and try only adding the code I provided earlier? I would like to see if you observe the same problem then.

    Best Regards,

    Tarek

  • Hello Tarek,

    I have tried to import the default Basic BLE project by adding only the lines of code but it has exactly the same result.
    We sent a message to the FAE to forward the problem and facilitate communication.

    Best Regards,

    Yohan

  • Hello Yohan, 

    Thank you so much for providing the packet sniffer log! We will begin analyzing it and get back to you ASAP. 

    Best Regards,

    Tarek

  • Hello Yohan,

    Thank you for your patience! When using an android device, I was finally able to recreate the issue you were mentioning. I have filed a ticket to have our R&D team take a look at this issue. In the meantime, a quick workaround to this problem would be:

    1. Go to the common folder of the project
    2. Unlink the following files: ( to unlink a file, simply copy the file, delete from the project, then paste the file back in it's original place)
      1. bleapputil_init.c (Inside the BLEAppUtil folder)
      2. ble_stack_api.c  (Inside the iCallBLE folder)
      3. ble_stack_api.h  (Inside the iCallBLE folder)
    3. Go to ble_stack_api.c file
    4. Scroll down to bleStack_initGatt function
    5. Comment out the GGS_AddService() and GATTServApp_AddService() functions. The code should now look like this:
    6. Build and Flash the project

    However, this will disable all the Generic Access characteristics. For more info on this API, in case you want to make modifications: https://software-dl.ti.com/simplelink/esd/simplelink_cc13x2_26x2_sdk/4.10.00.78/exports/docs/ble5stack/ble_user_guide/doxygen/ble/html/group___g_a_p_g_a_t_t_s_e_r_v_e_r.html#gadb5d755b466055f8a6d167a4b881c59f

    I hope this solves your problem! 

    Best Regards,

    Tarek

  • Hello Tarek,

    This solution works perfectly, thank you for your help !
    Best Regards,

    Yohan