Announcements

Equip yourself to optimize PSoc4 MCUs for Evs at the EV Webinar. Click here to register.

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

PSoC™ 4 Forum Discussions

KlJe_3653291
Level 2
Level 2
First like received First solution authored 5 replies posted

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.

0 Likes
1 Solution

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

View solution in original post

0 Likes
3 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

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

0 Likes

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;

0 Likes

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

0 Likes