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: Handling pairing failed events

Part Number: CC2340R5

Tool/software:

Hi,

I am a BLE peripheral device and I am doing pairing and bonding with a central device (mobile phone). As I have gone through your documentation, there are only few event masks available for handling pairing states.

BLEAPPUTIL_PAIRING_STATE_STARTED = (uint32_t)BV(0), //!< @ref GAPBOND_PAIRING_STATE_STARTED
BLEAPPUTIL_PAIRING_STATE_COMPLETE = (uint32_t)BV(1), //!< @ref GAPBOND_PAIRING_STATE_COMPLETE
BLEAPPUTIL_PAIRING_STATE_ENCRYPTED = (uint32_t)BV(2), //!< @ref GAPBOND_PAIRING_STATE_ENCRYPTED
BLEAPPUTIL_PAIRING_STATE_BOND_SAVED = (uint32_t)BV(3), //!< @ref GAPBOND_PAIRING_STATE_BOND_SAVED
BLEAPPUTIL_PAIRING_STATE_CAR_READ = (uint32_t)BV(4), //!< @ref GAPBOND_PAIRING_STATE_CAR_READ
BLEAPPUTIL_PAIRING_STATE_RPAO_READ = (uint32_t)BV(5), //!< @ref GAPBOND_PAIRING_STATE_RPAO_READ
BLEAPPUTIL_GENERATE_ECC_DONE = (uint32_t)BV(6) //!< @ref GAPBOND_GENERATE_ECC_DONE

I did  testing where my peripheral is initiating pairing request and on my central device (phone) I cancelled the pairing. But BLEAPPUTIL_PAIRING_STATE_COMPLETE stiil gets triggered in my application however. bond is not saved and a disconnection happens after that. Why BLEAPPUTIL_PAIRING_STATE_COMPLETE is getting triggered even if I cancel the pairing? If pairing fails due to some reason, how can I get the error state in my application as I dont see any event?

Please help

  • Hi !

    BLEAPPUTIL_PAIRING_STATE_COMPLETE is a pairing event mask flag. This means that it is actually a category of event, which can have different statuses. The status of your pairing can be read inside the pMsgData variable of your Pairing_pairStateHandler (Assuming you are using the basic_ble example). To read this variable, you would first need to cast it to a BLEAppUtil_PairStateData_t, and then read the status field.

    To see an example of this, the basic_ble example displays in the UART the status of the pairing connection in the app_pairing.c file :

    void Pairing_pairStateHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {
        switch (event)
        {
            case BLEAPPUTIL_PAIRING_STATE_STARTED:
            {
                MenuModule_printf(APP_MENU_PAIRING_EVENT, 0, "Pairing Status: Started - "
                                  "connectionHandle = "MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET
                                  "status = "MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET,
                                  ((BLEAppUtil_PairStateData_t *)pMsgData)->connHandle,
                                  ((BLEAppUtil_PairStateData_t *)pMsgData)->status);
    
                break;
            }
            
            // Code for other event masks ...
        }
    }

    In the case of you cancelling the pairing on your central device, the BLE stack will likely call the the function Pairing_pairStateHandler with the parameters GAPBOND_PAIRING_STATE_COMPLETE for the event, and SMP_PAIRING_FAILED_PASSKEY_ENTRY_FAILED for the pMsgData->status.

    You can read more about the possible status of each events in the BLE5 Stack API reference.

    Kind regards,
    Maxence

  • Hi Mathieu,

    Thanks for the clarification. It is working properly. I can read the failure events.