8 Replies Latest reply on Jul 4, 2018 8:13 AM by AnCi_2234676

    Bonding issues

    AnCi_2234676

      I am trying to connect, pair and bond my device (PSoC 6 using Just Works pairing) with an Android phone. It works at first, but if I disconnect and reconnect, when I try to access a characteristic that requires encryption, I get unpaired and disconnected. I am not sure why.

       

      From what I understand, Android phones use resolvable random addresses. I am not sure how I am supposed to handle this.

      It is also unclear to me how to handle the various security keys. Which keys should I generate and exchange?

      Where does Link Layer Privacy fit in all of this?

       

      Can somebody help me with this?

        • 1. Re: Bonding issues
          MeenakshiR_71

          Hello AnCi_2234676,

           

          Will it be possible to upload your project?

           

          Link layer privacy is required to Resolve Private address at the link layer (a feature of BLE 4.2) or to use Resolvable private address for advertisement. However, for your application you do not need LL privacy feature. You can refer to section 7 of AN99209 for complete details on Link Layer privacy or can read the BLE 4.2 spec as well .

           

          For your issue, are you calling Cy_BLE_StoreBondingData API till cy_ble_pendingFlashWrite is 0 to store the bonding data? Are you generating the keys and setting them for every connection?

           

          Regards,

          Meenakshi Sundaram R

          • 2. Re: Bonding issues
            AnCi_2234676

            Hi msur,

             

            Thanks for the reply. I can't really upload my project.

             

            I was able to make the bonding work with my parameters by modifying the example project CE212742, but I am having issues porting it to my project. It might have something to do with the fact that I am using the PSoC 6 in single core mode (only using the CM0p). Right now, my issue seems to be that the call to Cy_BLE_StoreBondingData() fail and returns CY_BLE_ERROR_FLASH_WRITE.

             

            Let me know if you have any idea why that would happen.

            • 3. Re: Bonding issues
              MeenakshiR_71

              Hello AnCi_2234676,

               

              Do you have Cy_SysEnableCM4() API call in your code? If not, can you call the API and in the CM4 code, put the core to deep sleep (if not using).

               

              If you have SysEnableCM4 in your code already, then I think I will have to take a look at the code to see what is happening.

               

              If you cannot upload the code, then  can you put a Breakpoint in "Cy_BLE_HAL_NvramWrite" API present in "cy_ble_hal_pvt.c" file and let me know in which line of code it fails (you will have to step till the "swtich(rc)" switch case and then see what is the value of rc).

               

              Regards,

              Meenakshi Sundaram R

              • 4. Re: Bonding issues
                AnCi_2234676

                Hi msur,

                 

                I have added the Cy_SysEnableCM4() and then put the CM4 to sleep. I still get the CY_BLE_ERROR_FLASH_WRITE.

                 

                I have added a breakpoint like you asked in Cy_BLE_HAL_NvramWrite() and the value of rc at the switch case is CY_FLASH_DRV_IPC_BUSY.

                 

                What does it tell you?

                • 5. Re: Bonding issues
                  MeenakshiR_71

                  CY_FLASH_DRV_IPC_BUSY can be a result of multiple cases.

                   

                  Since you are not uploading the project, you will need to do the debug for me

                   

                  Can you break in Cy_Flash_SendCmd API and let me which line of the API returns CY_FLASH_DRV_IPC_BUSY error? Also, this API will be called two times (Erase and Program) per Cy_BLE_HAL_NvramWrite() API, so let me know which call it fails.

                   

                  Since you do not use CM4, you can call Cy_SysDisableCM4() API in the beginning. This should narrow down "if" statement in the Cy_Flash_SendCmd API.

                  • 6. Re: Bonding issues
                    AnCi_2234676

                    Calling Cy_SysDisableCM4() has solved the flash error issue, but the bonding still doesn't work.

                     

                    After pairing, if I disconnect and reconnect, I need to pair again.

                     

                    I don't really care for privacy at the moment, so I would like for my device to use a public address, but it needs to work with an Android phone that uses a private address. All I need is for the bonding to work so I don't need to pair manually every time. Could you give me a list of steps that are required to do this so I can verify that I am doing the right things?

                     

                    Thanks

                    • 7. Re: Bonding issues
                      AnCi_2234676

                      I can share this file with you which contains the code I use that relates to BLE connection (I removed everything else).

                       

                      Let me know if you see an issue with it.

                       

                      Thanks

                      • 8. Re: Bonding issues
                        AnCi_2234676

                        I found the issue!

                         

                        I was casting the eventParam to the wrong type in CY_BLE_EVT_GAP_ENHANCE_CONN_COMPLETE since LL Privacy is enabled.

                        Bonding works fine now.

                         

                        Thanks for your help.