2 Replies Latest reply on Mar 13, 2016 11:01 PM by vikasv_56

    Want to use random static BLE address


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

      CYBLE_GAP_BD_ADDR_T addr;CyBle_GapGenerateDeviceAddress(&addr, CYBLE_GAP_RANDOM_STATIC_ADDR, NULL);CyBle_SetDeviceAddress(&addr);CyBle_GapSetIdAddress(&addr);

      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.



        • 1. Re: Want to use random static BLE address

          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
               // NOTE: THERE SHOULD BE AN API FOR THIS!!!
               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 ???

          • 2. Re: Want to use random static BLE address

            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.







            1 of 1 people found this helpful