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.

CC2642R: CC2652R: How to remove pairing capabilities from simple_peripheral project

Part Number: CC2642R
Other Parts Discussed in Thread: SYSCONFIG

CC26x2


Note: The following instructions have been written for SDK 3_40_00_02 but can be adapted to quite any SDK version (that is why I provided the sources but also the diff files). In addition, the code was written for CC2642R but can be adapted to all the devices of the family (CC2652R, CC2652P, CC1352R, CC1352P)

At the end of this instruction, your project won’t be able anymore to pair. The goal is to save space in FLASH and RAM memory.
This modification is slightly more advanced but it's worth the money!

How to do this?

  1. Import the project you want (the OOB simple_peripheral or the project where you have already removed the display, the secondary advertisement, the auto PHY functionalities and the connection parameters update functionalities [see here])

  2. Using SysConfig, disallow pairing: BLE > Bond Manager > Pairing Mode
    Here is a screenshot showing how to proceed. You can also use the SysConfig I have modified for you (it encloses the modifications we required to remove the display, the secondary advertisement, the auto PHY functionalities and the connection parameters update functionalities)



    Note: The warning raised by SysConfig is not due to the current modification. It was raised due to previous modification.

    Here is the syscfg file: 0218.simple_peripheral.syscfg

3. Do the following in simple_peripheral.c

    • Remove the callbacks SimplePeripheral_passcodeCb() and SimplePeripheral_pairStateCb()
    • Remove the structure SimplePeripheral_BondMgrCBs. Instead of passing a reference to the structure we just deleted to the GAPBondMgr (threw the function GAPBondMgr_Register()), pass NULL
    • Remove the function SimplePeripheral_processPairState() and its calls.
    • Remove the function SimplePeripheral_processPasscode() and its calls.
    • The definition of the structure types spPairStateData_t and spPasscodeData_t can be removed

Here are the diff file and the file you are supposed to get if you also removed the display, the secondary advertisement, the auto PHY functionalities and the connection parameters update functionalities:

simple_peripheral_remove_pairing_capabilities.diff
--- C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\simple_peripheral_without_update_param.c	Wed Feb 12 15:35:38 2020
+++ C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\simple_peripheral_SIMPLE.c	Wed Feb 12 16:27:29 2020
@@ -139,28 +139,6 @@
   void    *pData;               // pointer to message
 } spEvt_t;
 
-// Container to store passcode data when passing from gapbondmgr callback
-// to app event. See the pfnPairStateCB_t documentation from the gapbondmgr.h
-// header file for more information on each parameter.
-typedef struct
-{
-  uint8_t state;
-  uint16_t connHandle;
-  uint8_t status;
-} spPairStateData_t;
-
-// Container to store passcode data when passing from gapbondmgr callback
-// to app event. See the pfnPasscodeCB_t documentation from the gapbondmgr.h
-// header file for more information on each parameter.
-typedef struct
-{
-  uint8_t deviceAddr[B_ADDR_LEN];
-  uint16_t connHandle;
-  uint8_t uiInputs;
-  uint8_t uiOutputs;
-  uint32_t numComparison;
-} spPasscodeData_t;
-
 // Container to store advertising event data when passing from advertising
 // callback to app event. See the respective event in GapAdvScan_Event_IDs
 // in gap_advertiser.h for the type that pBuf should be cast to.
@@ -255,13 +233,6 @@
 static void SimplePeripheral_performPeriodicTask(void);
 static void SimplePeripheral_updateRPA(void);
 static void SimplePeripheral_clockHandler(UArg arg);
-static void SimplePeripheral_passcodeCb(uint8_t *pDeviceAddr, uint16_t connHandle,
-                                        uint8_t uiInputs, uint8_t uiOutputs,
-                                        uint32_t numComparison);
-static void SimplePeripheral_pairStateCb(uint16_t connHandle, uint8_t state,
-                                         uint8_t status);
-static void SimplePeripheral_processPairState(spPairStateData_t *pPairState);
-static void SimplePeripheral_processPasscode(spPasscodeData_t *pPasscodeData);
 static void SimplePeripheral_charValueChangeCB(uint8_t paramId);
 static status_t SimplePeripheral_enqueueMsg(uint8_t event, void *pData);
 static uint8_t SimplePeripheral_addConn(uint16_t connHandle);
@@ -281,13 +252,6 @@
 /*********************************************************************
  * PROFILE CALLBACKS
  */
-
-// GAP Bond Manager Callbacks
-static gapBondCBs_t SimplePeripheral_BondMgrCBs =
-{
-  SimplePeripheral_passcodeCb,       // Passcode callback
-  SimplePeripheral_pairStateCb       // Pairing/Bonding state Callback
-};
 
 // Simple GATT Profile Callbacks
 static simpleProfileCBs_t SimplePeripheral_simpleProfileCBs =
@@ -468,7 +432,7 @@
   SimpleProfile_RegisterAppCBs(&SimplePeripheral_simpleProfileCBs);
 
   // Start Bond Manager and register callback
-  VOID GAPBondMgr_Register(&SimplePeripheral_BondMgrCBs);
+  VOID GAPBondMgr_Register(NULL);
 
   // Register with GAP for HCI/Host messages. This is needed to receive HCI
   // events. For more information, see the HCI section in the User's Guide:
@@ -717,14 +681,6 @@
 
     case SP_ADV_EVT:
       SimplePeripheral_processAdvEvent((spGapAdvEventData_t*)(pMsg->pData));
-      break;
-
-    case SP_PAIR_STATE_EVT:
-      SimplePeripheral_processPairState((spPairStateData_t*)(pMsg->pData));
-      break;
-
-    case SP_PASSCODE_EVT:
-      SimplePeripheral_processPasscode((spPasscodeData_t*)(pMsg->pData));
       break;
 
     case SP_PERIODIC_EVT:
@@ -1116,110 +1072,6 @@
   }
 }
 
-
-/*********************************************************************
- * @fn      SimplePeripheral_pairStateCb
- *
- * @brief   Pairing state callback.
- *
- * @return  none
- */
-static void SimplePeripheral_pairStateCb(uint16_t connHandle, uint8_t state,
-                                         uint8_t status)
-{
-  spPairStateData_t *pData = ICall_malloc(sizeof(spPairStateData_t));
-
-  // Allocate space for the event data.
-  if (pData)
-  {
-    pData->state = state;
-    pData->connHandle = connHandle;
-    pData->status = status;
-
-    // Queue the event.
-    if(SimplePeripheral_enqueueMsg(SP_PAIR_STATE_EVT, pData) != SUCCESS)
-    {
-      ICall_free(pData);
-    }
-  }
-}
-
-/*********************************************************************
- * @fn      SimplePeripheral_passcodeCb
- *
- * @brief   Passcode callback.
- *
- * @return  none
- */
-static void SimplePeripheral_passcodeCb(uint8_t *pDeviceAddr,
-                                        uint16_t connHandle,
-                                        uint8_t uiInputs,
-                                        uint8_t uiOutputs,
-                                        uint32_t numComparison)
-{
-  spPasscodeData_t *pData = ICall_malloc(sizeof(spPasscodeData_t));
-
-  // Allocate space for the passcode event.
-  if (pData )
-  {
-    pData->connHandle = connHandle;
-    memcpy(pData->deviceAddr, pDeviceAddr, B_ADDR_LEN);
-    pData->uiInputs = uiInputs;
-    pData->uiOutputs = uiOutputs;
-    pData->numComparison = numComparison;
-
-    // Enqueue the event.
-    if(SimplePeripheral_enqueueMsg(SP_PASSCODE_EVT, pData) != SUCCESS)
-    {
-      ICall_free(pData);
-    }
-  }
-}
-
-/*********************************************************************
- * @fn      SimplePeripheral_processPairState
- *
- * @brief   Process the new paring state.
- *
- * @return  none
- */
-static void SimplePeripheral_processPairState(spPairStateData_t *pPairData)
-{
-  uint8_t state = pPairData->state;
-
-  switch (state)
-  {
-    case GAPBOND_PAIRING_STATE_STARTED:
-      break;
-
-    case GAPBOND_PAIRING_STATE_COMPLETE:
-      break;
-
-    case GAPBOND_PAIRING_STATE_ENCRYPTED:
-      break;
-
-    case GAPBOND_PAIRING_STATE_BOND_SAVED:
-      break;
-
-    default:
-      break;
-  }
-}
-
-/*********************************************************************
- * @fn      SimplePeripheral_processPasscode
- *
- * @brief   Process the Passcode request.
- *
- * @return  none
- */
-static void SimplePeripheral_processPasscode(spPasscodeData_t *pPasscodeData)
-{
-  // Send passcode response
-  GAPBondMgr_PasscodeRsp(pPasscodeData->connHandle , SUCCESS,
-                         B_APP_DEFAULT_PASSCODE);
-}
-
 /*********************************************************************
  * @fn      SimplePeripheral_enqueueMsg
  *
   2388.simple_peripheral_SIMPLE.C

Build and test your program. Except the eventual warning raised by SysConfig due to modification we did earlier, everything should build and work smoothly.

Could we do better? Yes but this modification is quite advanced!

In summary, here we have a software that does not use anymore the bonding/pairing possibilities provided by the BLE stack. However a non-negligible amount of FLASH is consumed by some calls to the bond manager functions (you can find these calls inside osal_icall_ble.c and icall_hci_tl.c)… this is useless and we are going to find a way to avoid this. You will see the code in these two files contains a few #ifdef used to do some conditional compilation.

The file ti_build_config.opt (in the folder Debug/syscfg of your project) contains the symbols used for the conditional compilation of your project (* Note: as you will understand latter, this file is generated by SysConfig and you might be required to launch a first build if the file has not been yet generated).
As you have seen in osal_icall_ble.c and icall_hci_tl.c when the symbol GAP_BOND_MGR is defined, some extra portions of code are compiled. To avoid this, we need to *not* declare the symbol GAP_BOND_MGR.

However, we cannot modify the content of ti_build_config.opt because all the modifications will be erased at each new compilation. Then we have two solutions:

OR

  • Change the way SysConfig is generating the file. In fact SysConfig is using a template we can basically modify. The template we need to consider is in your SDK folder under source\ti\ble5stack\.meta\templates and is named build_config.opt.xdt. As you can see, the symbol GAP_BOND_MGR is supposed to be declared based on a Boolean condition. However, this Boolean condition is always true for this project (believe me or have a look into source\ti\ble5stack\.meta\ble.syscfg.js). So we are going to modify the content of build_config.opt.xdt in order to comment the declaration of the symbol GAP_BOND_MGR.

Here is the diff and the content of the build_config.opt.xdt file:

build_config.opt.xdt.diff
--- C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\build_config.opt.xdt	Wed Feb 12 18:24:28 2020
+++ C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\build_config.opt_SIMPLE.xdt	Wed Feb 12 17:54:18 2020
@@ -24,7 +24,7 @@
 % if(ble.bondManager) {
 
 /* Include GAP Bond Manager */
--DGAP_BOND_MGR
+/*-DGAP_BOND_MGR*/
 %}
 %
 % if(ble.L2CAPCOC) {
   build_config.opt.xdt

/!\ Be careful, by modifying the file build_config.opt.xdt, you modify the way SysConfig is generating ALL the projects based on this SDK!

Here is the content of the file ti_build_config.opt the toolchain should use (no matter which option you chose):

ti_build_config.opt.diff
--- C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\ti_build_config.opt	Wed Feb 12 18:26:55 2020
+++ C:\ti\simplelink_cc13x2_26x2_sdk_3_40_00_02\examples\rtos\CC26X2R1_LAUNCHXL\ble5stack\simple_peripheral\Application\ti_build_config_SIMPLE.opt	Wed Feb 12 17:54:47 2020
@@ -9,7 +9,7 @@
 -DHOST_CONFIG=PERIPHERAL_CFG
 
 /* Include GAP Bond Manager */
--DGAP_BOND_MGR
+/*-DGAP_BOND_MGR*/
 
 /* Include Transport Layer (Full or PTM) */
 -DHCI_TL_NONE
   ti_build_config_SIMPLE.OPT

Build and test your program. Except the eventual warning raised by SysConfig due to modification we did earlier, everything should build and work smoothly.