You are here

Want to use random static BLE address | Cypress Semiconductor

Want to use random static BLE address

Summary: 2 Replies, Latest post by VAVC on 13 Mar 2016 11:01 PM PDT
Verified Answers: 0
Last post
Log in to post new comments.
jedwards_1453761's picture
4 posts

I am trying to change the BLE address to a "random static" address and have tried the following API calls: 

CyBle_GapGenerateDeviceAddress(&addr, CYBLE_GAP_RANDOM_STATIC_ADDR, NULL);

The function to generate the address works but neither of the functions to set it seem to work.  When I start advertising the address that shows up in CySmart is the original factory silicon generated address and not my newly generated address.





jedwards_1453761's picture
4 posts

After several hours of looking through the Cypress source code I found a solution but it feels like a hack because I am required to modify a global variable that is within the automatically generated source code.

Here is the code I added to the BLE event handler call back function:

 *                       General Events

 case CYBLE_EVT_STACK_ON: /* This event is received when the component is Started */
 // Generate a random static address
 apiResult = CyBle_GapGenerateDeviceAddress(&localAddr, CYBLE_GAP_RANDOM_STATIC_ADDR, NULL);
 if(CYBLE_ERROR_OK == apiResult)
     // Set the device address
     // Change the address type in the discovery parameters
     cyBle_discoveryParam.ownAddrType = CYBLE_GAP_ADDR_TYPE_RANDOM;
     // Failed to generate an address so just use
     // the default "public" Cypress address
     localAddr.type = 0u;
 // Show the address we are using...
 DBG_PRINTF("Bluetooth On, addr: ");
 for(i = CYBLE_GAP_BD_ADDR_SIZE; i > 0u; i--)
     DBG_PRINTF("%2.2x", localAddr.bdAddr[i-1u]);


This line is the one that bothers me:

cyBle_discoveryParam.ownAddrType = CYBLE_GAP_ADDR_TYPE_RANDOM;


I figured this out when I noticed this comment in BLE.c

/* This variable of type CYBLE_GAPP_DISC_MODE_INFO_T is present only when 
   the BLE component is configured for Peripheral GAP role or Central and 
   Peripheral GAP role. It contains the Advertisement settings and also the 
   Advertisement and Scan response data parameters entered in the customizer.
   This variable can be used by advanced users to change Advertisement settings,
   Advertisement or Scan response data in runtime. 
CYBLE_GAPP_DISC_MODE_INFO_T cyBle_discoveryModeInfo =
    0x02u,      /* uint8 discMode */
    0x001Eu,    /* uint16 advTo */


Maybe a Cypress employee can let us know if this is just a case of the component customizer not being mature or a missing API or ???



VAVC's picture
Cypress Employee
506 posts

By default the component allows you set the public address.

If user wants to change it to random or resolvable private address , use has  to edit the global variable

as you did.






Log in to post new comments.