PSoC6 BLE setting a fixed pass key

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
chcac_2757786
Level 1
Level 1

I am trying to use a fixed pass key on a PSoC6 pioneer kit sample project. I'm using the BLE Navigation code example and I've made two modifications:

1) Added the following call to the  CY_BLE_EVT_STACK_ON handler to set the fixed pass key to 123456:

           cy_stc_ble_gap_auth_fix_pk_info_t pk;

            pk.bdHandle = appConnHandle.bdHandle;

            pk.fixedPassKey = 123456;

            pk.isFixed = CY_BLE_GAP_PASSKEY_FIXED;

            Cy_BLE_GAP_FixAuthPassKey(&pk);

            if(apiResult != CY_BLE_SUCCESS)

            {

                DBG_PRINTF("Cy_BLE_GAP_FixAuthPassKey failed: %d", apiResult);

            }

2) Changed the I/O Capabilities in the Security configuration (in BLE schematic block) to "Display".  This is required per the PDL documentation of the Cy_BLE_GAP_FixAuthPassKey() API call.

When I use CySmart to connect to the device in iOS, it does bring up the pairing window.  However, the passkey displayed on the Pioneer kit debug console is a random passkey (not the 123456 passkey I had set before).

If I enter the "123456" pass key on iOS, the console shows the following error : "CY_BLE_EVT_GAP_AUTH_FAILED, reason: CONFIRM_VALUE_NOT_MATCH"

However, if I enter the random pass key displayed on the console, the Auth successfully completes.  So it seems like I am not setting/using the fixed passkey.

Am I doing something wrong, or is there a bug with this API?

0 Likes
1 Solution
VaisakhK_66
Employee
Employee
10 replies posted 5 replies posted First question asked

Hello Chris,

If you need to use a fixed passkey, you need to set this during the CY_BLE_EVT_GAP_AUTH_REQ event and not during CY_BLE_EVT_STACK_ON event, the reason being the function uses the parameter which requires the bdHandle. The bdHandle is not available during the STACK ON event. You can modify your code as below:

case CY_BLE_EVT_GAP_AUTH_REQ:

        {

            DBG_PRINTF(("\r\nCY_BLE_EVT_GAP_AUTH_REQ\r\n");

            cy_stc_ble_gap_auth_info_t gapAuthInfo = *(cy_stc_ble_gap_auth_info_t*)eventParameter;

          

            /* appConnHandle should be set during the CY_BLE_EVT_GAP_DEVICE_CONNECTED event */

            cy_ble_configPtr-> authInfo[CY_BLE_SECURITY_CONFIGURATION_0_INDEX].bdHandle

                    = appConnHandle.bdHandle;

            pk.fixedPassKey = 123456;

            pk.isFixed = CY_BLE_GAP_PASSKEY_FIXED;

            pk.bdHandle = appConnHandle.bdHandle;

            Cy_BLE_GAP_FixAuthPassKey(&pk);

           

            apiResult = Cy_BLE_GAPP_AuthReqReply(&(cy_ble_configPtr-> authInfo[CY_BLE_SECURITY_CONFIGURATION_0_INDEX]));

            

            break;

        }

Let me know if this helps.

Thanks,

Vaisakh

View solution in original post

3 Replies
VaisakhK_66
Employee
Employee
10 replies posted 5 replies posted First question asked

Hello Chris,

If you need to use a fixed passkey, you need to set this during the CY_BLE_EVT_GAP_AUTH_REQ event and not during CY_BLE_EVT_STACK_ON event, the reason being the function uses the parameter which requires the bdHandle. The bdHandle is not available during the STACK ON event. You can modify your code as below:

case CY_BLE_EVT_GAP_AUTH_REQ:

        {

            DBG_PRINTF(("\r\nCY_BLE_EVT_GAP_AUTH_REQ\r\n");

            cy_stc_ble_gap_auth_info_t gapAuthInfo = *(cy_stc_ble_gap_auth_info_t*)eventParameter;

          

            /* appConnHandle should be set during the CY_BLE_EVT_GAP_DEVICE_CONNECTED event */

            cy_ble_configPtr-> authInfo[CY_BLE_SECURITY_CONFIGURATION_0_INDEX].bdHandle

                    = appConnHandle.bdHandle;

            pk.fixedPassKey = 123456;

            pk.isFixed = CY_BLE_GAP_PASSKEY_FIXED;

            pk.bdHandle = appConnHandle.bdHandle;

            Cy_BLE_GAP_FixAuthPassKey(&pk);

           

            apiResult = Cy_BLE_GAPP_AuthReqReply(&(cy_ble_configPtr-> authInfo[CY_BLE_SECURITY_CONFIGURATION_0_INDEX]));

            

            break;

        }

Let me know if this helps.

Thanks,

Vaisakh

Hi Vaisakh,

(Edited my previous reply).

It looks like that worked, thanks for the suggestion!

Note for Cypress: The reason I had put the Cy_BLE_GAP_FixAuthPassKey() call in the CY_BLE_EVT_STACK_ON handler was because that is what the PDL documentation and source header said for that API call.

Thanks,

Chris

0 Likes
VaisakhK_66
Employee
Employee
10 replies posted 5 replies posted First question asked

Hello Chris,

Good to know that your issue got resolved!

Thanks for pointing out the error in our PDL documentation ... We shall update the PDL documentation accordingly.

Regards,

Vaisakh

0 Likes