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: CC2640R2 Pairing Passkey Problem

Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2640

Hi there,

I am making a POC with CC2640R2 chip with simplelink_cc2640r2_sdk_1_40_00_45 stack. My code is running on a custom designed board and everything related with HW looks fine. Before I start I wanted to mention that, I am following following page: file:///C:/ti/simplelink_cc2640r2_sdk_1_40_00_45/docs/ble5stack/ble_user_guide/html/ble-stack-5.x/gapbondmngr.html

I would like to use pair with my peripheral device with central device (PC/Mobile Phone) where Initiator (Central Device) has Keyboard and Display and Responder - My Device - (Peripheral Device) has Display YESNO. I would like to use PassKey Entry for LE Legacy and Numaric Comparison for Secure Connection.

I use the SimplePeripheral Project as base and wrote my code on top of that. Here is the build_config.opt on my Stack Project.

-DHOST_CONFIG=PERIPHERAL_CFG
-DGAP_BOND_MGR
-DBLE_V41_FEATURES=L2CAP_COC_CFG
-DBLE_V42_FEATURES=SECURE_CONNS_CFG+PRIVACY_1_2_CFG
-DHCI_TL_NONE


My Stack project has "OSAL_SNV=1" Preprocessor define

On the application project, I defined "MAX_PDU_SIZE=135" and my minimum heap size is set to 4500 on app_ble.cfg file as following:

var Memory = xdc.useModule('xdc.runtime.Memory');
var HEAPMGR_CONFIG = 1;
var HEAPMGR_SIZE   = 4500;


Here are my gap parameters configured as:

    // Setup Antenna Power
    {
        HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_0_DBM);
    }
    
    // Advertisement Parameters
    {
        uint8_t initialAdvertEnable = TRUE;                             // Device starts advertising upon initialization of GAP
        uint16_t advertOffTime = DEFAULT_ADVERTISE_OFF_TIME;
        uint8_t enableUpdateRequest = DEFAULT_ENABLE_UPDATE_REQUEST;
        uint16_t desiredMinInterval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
        uint16_t desiredMaxInterval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
        uint16_t desiredSlaveLatency = DEFAULT_DESIRED_SLAVE_LATENCY;
        uint16_t desiredConnTimeout = DEFAULT_DESIRED_CONN_TIMEOUT;
        uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;
        
        // Set the Peripheral GAPRole Parameters
        GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),&initialAdvertEnable);
        GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t),&advertOffTime);
        GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData),scanRspData);
        GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
        GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t),&enableUpdateRequest);
        GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t),&desiredMinInterval);
        GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t),&desiredMaxInterval);
        GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t),&desiredSlaveLatency);
        GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t),&desiredConnTimeout);
        
        GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt);
        GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt);
        GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt);
        GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt);
    }
    
    // Set the GAP Characteristics
    {
        uint8_t gapPeripheralPrivacyFlag = GAP_PERIPHERAL_PRIVACY_FLAG;
        uint8_t gapPeripheralConnectionParam[8] = GAP_PERIPHERAL_CONNECTION_PARAM;
        
        GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (void *) attDeviceName);
        GGS_SetParameter(GGS_PERI_PRIVACY_FLAG_ATT, sizeof(uint8), &gapPeripheralPrivacyFlag);
        GGS_SetParameter(GGS_PERI_CONN_PARAM_ATT, 8, &gapPeripheralConnectionParam);
        GAP_SetParamValue(TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL);
    }
    
    // Bonding Parameters
    {
        uint32_t passkey = DEFAULT_PAIRING_PIN_CODE;
        uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;   // Don't send a pairing request after connecting; the peer device must initiate pairing
        uint8_t mitm = TRUE;    // Use authenticated pairing: require passcode.
        uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_YES_NO;
        uint8_t bonding = TRUE;
        uint8_t gapbondSecure = GAPBOND_SECURE_CONNECTION_ALLOW;
        
        GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t),&passkey);
        GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
        GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
        GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
        GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
        GAPBondMgr_SetParameter(GAPBOND_SECURE_CONNECTION, sizeof(uint8_t), &gapbondSecure);
        
        // Disable Advertisement Timeout
        GAP_SetParamValue(TGAP_GEN_DISC_ADV_MIN, 0);
        GAP_SetParamValue(TGAP_LIM_ADV_TIMEOUT, 0);
        
        uint8_t u8VarWithNumber = 15;     // 15*18=270 byte buffer size
        GATTServApp_SetParameter(GATT_PARAM_NUM_PREPARE_WRITES, 1, &u8VarWithNumber);
    }
    
    .....
    
#if defined (BLE_V42_FEATURES) && (BLE_V42_FEATURES & PRIVACY_1_2_CFG)
    // Initialize GATT Client
    GATT_InitClient();
    
    // This line masks the Resolvable Private Address Only (RPAO) Characteristic
    // in the GAP GATT Server from being detected by remote devices. This value
    // cannot be toggled without power cycling but should remain consistent across
    // power-cycles. Removing this command when Privacy is used will cause this
    // device to be treated in Network Privacy Mode by bonded devices - this means
    // that after disconnecting they will not respond to this device's PDUs which
    // contain its Identity Address.
    // Devices wanting to use Network Privacy Mode with other BT5 devices, this
    // line should be commented out.
    // GGS_SetParamValue(GGS_DISABLE_RPAO_CHARACTERISTIC); // ----- Not interested in RPA for now.
#endif // BLE_V42_FEATURES & PRIVACY_1_2_CFG
    
#if !defined (USE_LL_CONN_PARAM_UPDATE)
    // Get the currently set local supported LE features
    // The will result in a HCI_LE_READ_LOCAL_SUPPORTED_FEATURES event that
    // will get received in the main task processing loop. At this point,
    // feature bits can be set / cleared and the features can be updated.
    HCI_LE_ReadLocalSupportedFeaturesCmd();
#endif // !defined (USE_LL_CONN_PARAM_UPDATE)
    
    ......






    I also registered the gapBondCBs

static gapBondCBs_t XXX_BondMgrCBs =
{
    (pfnPasscodeCB_t)XXX_passcodeCB, // Passcode callback
    XXX_pairStateCB                   // Pairing / Bonding state Callback
};

where;


static void XXX_passcodeCB(uint8_t *deviceAddr, uint16_t connHandle,
                             uint8_t uiInputs, uint8_t uiOutputs, uint32_t numComparison)
{
    gapPasskeyNeededEvent_t *pData;
    
    // Allocate space for the passcode event.
    if ((pData = ICall_malloc(sizeof(gapPasskeyNeededEvent_t))))
    {
        memcpy(pData->deviceAddr, deviceAddr, B_ADDR_LEN);
        pData->connectionHandle = connHandle;
        pData->uiOutputs = uiOutputs;
        pData->uiInputs = uiInputs;
        pData->numComparison = numComparison;
        pData->opcode = GAP_PASSKEY_NEEDED_EVENT;
        
        // Enqueue the event.
        XXX_enqueueMsg(XXX_PASSCODE_NEEDED_EVT, NULL, (uint8_t *) pData);
    }
}

static void XXX_processPasscode(gapPasskeyNeededEvent_t *pData)
{
    // Use static passcode
    uint32_t passcode = DEFAULT_PAIRING_PIN_CODE;
    //Display_print1(dispHandle, MR_ROW_SECURITY, 0, "Passcode: %d", passcode);
    // Send passcode to GAPBondMgr
    GAPBondMgr_PasscodeRsp(pData->connectionHandle, SUCCESS, passcode);
}




However, I never receive a PIN Entry on my central device. Can you tell me a little bit about what can be wrong. I spent a lot of time and played with different parameters for Bonding Parameters. However, still there is no result yet.

I thank you in advance!

  • Can anyone chime in?

  • Can you take a BLE air sniffer capture showing the pairing request/response and subsequent SMP operations? That would be a good starting point.

    Best wishes
  • Hi there,

    I sniffed the air traffic with BPA low energy and here are the screenshots for SMP.

    Thanks for helping!

  • Interesting. By chance is your default passcode 000000? It's proceeding on with successful pairing as if the key code was entered correctly on the Initiator.

    Best wishes
  • Exactly, my default pairing passcode was 000000. When I changed it to 123456 my central device rejects the pairing as following. Can you elaborate a little bit why I fail and how can I fix this?

    Thank you,

  • It looks like you need to work with the BLE provider for your central device(s) as they are not prompting for the passcode as per the SMP section of the BT core specification.

    Beyond that, have you tried setting your IOCap as "DisplayOnly" to see if that changes the behavior for this peer device? I know that will preclude LESC on other devices but it would be an interesting experiment with this device which doesn't support LESC anyway.

    Best wishes
  • Hi there,

    I am using Windows 10 machine with latest updates. It has BCM20702A0 external BT Dongle. With my CC2640 with tirtos_simplelink_2_13_00_06 stack I can successfully do passcode pairing when I set the BT Stack to 4.1 configuration.

    With my CC2640R2, when I set the ioCap to GAPBOND_IO_CAP_DISPLAY_ONLY by doing:

    uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;

    GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);

    I also set the passcode is to "000000".

    At the same time printing UART logs for gaprole_States_t on XXX_processStateChangeEvt(gaprole_States_t newState) and states with status on XXX_processPairStateEvt(uint8_t state, uint8_t status). Here are the logs:

    GAP State: 2 // GAPROLE_ADVERTISING

    GAP State: 6 // GAPROLE_CONNECTED

    Pair State: 0 Status: 0 // GAPBOND_PAIRING_STATE_STARTED

    Pair State: 3 Status: 0 // GAPBOND_PAIRING_STATE_BOND_SAVED

    Pair State: 5 Status: 0x14 // GAPBOND_PAIRING_STATE_RPAO_READ + ???

    Pair State: 4 Status: 0x14 // GAPBOND_PAIRING_STATE_CAR_READ + ???

    Note: These state and status codes are the same for when I set the ioCap to GAPBOND_IO_CAP_DISPLAY_YES_NO as well.

    Question is what does 0x14 status mean? I could not find in anywhere. I am also attaching the screenshots of sniffer again.

  • Hi,

    Status 0x14 means bleNotConnected. See bcomdef.h.

    My best guess is they are getting into a different state based on the controller version or something else related to privacy.
    What is the Windows 10 build revision?

    Best wishes
  • Hi there,

    Thank you for all responsive answers. I am running Windows 10 Pro Version 1067 OS Build: 14393.1715.

    Debugging is getting more interesting: When I try to pair with an Android Nexus 6 Phone running Android 7.1.1, it fails to continue after connected. Please see the attached screenshots. To me for now, it seems like the problem on CC2640R2 side.

  • Hi dnz,

    Of course, we are always guilty until proven otherwise :)

    It's difficult to make a conclusion from your sniffer screen shots (this is why we request the complete file) but I don't see any data PDUs after the CONNECT_IND. This would imply that the master (i.e., the handset) didn't transmit the first data PDU. Any thoughts on this?

    Best wishes