3 Replies Latest reply on Feb 20, 2020 3:35 AM by GaneshD_41

    Random static BLE address gives same value on two chips

    KlJe_3653291

      We would like to use Random static address and tried to use below code:

       

                      char_t buffer[DEVICE_ADV_NAME] = {0};

                      CYBLE_GAP_BD_ADDR_T localAddr;

                      // Generate a random static address

                      CyBle_GapGenerateDeviceAddress(&localAddr, CYBLE_GAP_RANDOM_STATIC_ADDR, NULL);

                      // Set the device address

                      CyBle_SetDeviceAddress(&localAddr);

                      CyBle_GapSetIdAddress(&localAddr);

       

                      // Change the address type in the discovery parameters

                      cyBle_discoveryParam.ownAddrType = CYBLE_GAP_ADDR_TYPE_RANDOM;

       

       

      We now see that the address change from the public static address to random static address but when we try it on two different devices we get the

      same address C0:49:29:19:95:80

       

      is the BLE random generator not random? is done init of the BLE random generator needed with a seed to generate pseudo random addresses?

       

      We use BLE 4100 chipset. tested with BLE 3.10 and 3.54 components.

        • 1. Re: Random static BLE address gives same value on two chips
          GaneshD_41

          Hi,

           

          >>"is the BLE random generator not random?"

          Cypress--> Yes. The random number generator in PSoC 4BLE is not fully random. It uses instant clock value of the inernal clock to generate the random number. We recommend you the following steps to generate random number for your application on every startup.

           

          1. You can use an Emulated EEPROM component and store some 32 bit random value seed in the flash.

          2. On every start-up read the random value and add some value to it and call the API CyBle_SetSeedForRandomGenerator(seed);to generate the random number during the initialization.

          3. Now you can call the API CyBle_GapGenerateDeviceAddress(&localAddr, CYBLE_GAP_RANDOM_STATIC_ADDR, NULL); to generate the actual random address.

           

          Please find the emulated EEPROM code example attached with this project.

           

          Thanks and regards

          Ganesh

           

           

          • 2. Re: Random static BLE address gives same value on two chips
            KlJe_3653291

            I was able to get CyBle_GapGenerateDeviceAddress to give a random address back in LocalAddr

             

            But the actual address used physical did not change to this when we call below code, the Random address seen by CySmart is still C0:49:29:19:95:80

              // Set the device address

                            CyBle_SetDeviceAddress(&localAddr);

                            CyBle_GapSetIdAddress(&localAddr);

             

                            // Change the address type in the discovery parameters

                            cyBle_discoveryParam.ownAddrType = CYBLE_GAP_ADDR_TYPE_RANDOM;

            • 3. Re: Random static BLE address gives same value on two chips
              GaneshD_41

              Hi,

               

              Please find the attached project. In main() please clear the SFLASH rows using following lines:

              uint8 row1[256]={0};

              uint8 seed=1;

                      CySysSFlashWriteUserRow(0,row1);

                      CySysSFlashWriteUserRow(1,row1);

                      CySysSFlashWriteUserRow(2,row1);

                      CySysSFlashWriteUserRow(3,row1);

               

               

              In STACK ON event we have used following sequence of APIs to generate random address.

               

                      cyBle_discoveryParam.ownAddrType = CYBLE_GAP_ADDR_TYPE_RANDOM;

                      CYBLE_GAP_BD_ADDR_T myaddress;    

                      myaddress.type=0x01;

                      CyBle_SetSeedForRandomGenerator(seed);

                      CyBle_GapGenerateDeviceAddress(&myaddress, CYBLE_GAP_RANDOM_STATIC_ADDR, NULL);

                      CyBle_GapSetIdAddress(&myaddress);

                      CyBle_SetDeviceAddress(&myaddress);

               

              Please note that you have to use different value of seed everytime to change the address. For that you can use Emulated EEPROM and store the previous seed value inside flash. Upon bootup you can read the Emulated EEPROM and get the previous seed value, use it, update it and store it back to the Flash using Emulated EEPROM APIs.

               

              Thanks

              Ganesh