This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Randomly generated address fails when stack role is changed

Other Parts Discussed in Thread: BLE-STACK, CC2650, CC2640

My custom board is currently set up as a peripheral, but I am trying to change it to be a broadcaster, however when I change the stack from peripheral to broadcaster the device no longer gets a randomly generated address even though I haven't changed the app at all. 

I believe its the from the GAP_ConfigDeviceAddr(ADDRMODE_STATIC, NULL) function. 

Any ideas as to why changing the stack would cause this function to fail? Instead it just keeps the hard coded address from the simple_peripheral example

  • Hi Olivia,

    Which device and SDK are you using? Is your application switching between being a peripheral and a broadcaster in your application?
  • Hi Jessica, 

    I am using a custom device and my SDK is Code Composer Studio version 7. The application is being changed from a peripheral to a broadcaster because my project no longer needs connections, but it does not switch back and forth in the program. The application works fine until I try and change the stack configuration from peripheral to broadcaster. Then the program runs but no random address is generated and it keeps the original hardcoded address.

  • Olivia,

    Are you using a CC2640R2 or CC26x2 based device? What Simplelink SDK are you using? Have you tried looking at our multirole example?
  • Hi Jessica, 

    I am using a CC2640R2 based device, I have tried looking at all the examples however I don't want multiple roles at the same time. I want to get rid of the peripheral role and replace it with broadcaster. 

    The SDK is simplelink ble-stack 2.2.2

  • Hi Olivia,

    Thanks for the information. I also want to check if you are using BLE 4.2 or BLE 5? What steps did you take to convert to broadcaster? Have you looked at this guide yet? If you are trying to use random addressing, can you tell me why you are using ADDRMODE_STATIC with GAP_ConfigDeviceAddr()? Also have you looked at the Simple_Broadcaster example?

  • Hi Jessica, 

    I am using BLE 4.2. The steps I took to convert to broadcaster was to start with the simple_broadcaster example and re-add the functionalities that I wanted to keep from my peripheral application. I am using static for functionality of some of the other parts of the application such as logs. 

    My main concern is that the application runs fine when it has the peripheral stack, but as soon as I change the stack to broadcaster it runs fine, it just no longer has a generated address.

  • Hi Olivia,

    When you say random resolvable address, I'm assuming you mean Random Resolvable Private Address? Are you calling GAP_ConfigDeviceAddr() anywhere in your peripheral code or broadcaster code? In the out-of-box examples, it looks like simple peripheral should have been using a public address.
  • Olivia,

    To configure random addresses, you will need to call:
    GAP_ConfigDeviceAddr(ADDRMODE_PRIVATE_RESOLVE);
    GAP_SetParamValue(GAP_PARAM_PRIVATE_ADDR_INT, 5);
    Where the 5 is a place holder for whatever time you want your program to generate a new random address. These functions should be called after GAP_DeviceInit() and should not be called during scanning or advertising.

    You can get more information here: dev.ti.com/.../privacy.html
  • Hi Jessica, 

    I am calling GAPRole_StartDevice() (which calls GAP_DeviceInit()), then I call GAP_ConfigDeviceAddr(), but I am using a static address that should only change when the device is turned on, then it should keep that address until it turns off again. I have checked and advertising is not enabled until after I call configDeviceAddr() and it runs perfectly when I have the stack set up to use the peripheral libraries (and osal_icall_ble.c file). However, when I change the stack to use the broadcaster libraries (and osal_icall_ble.c file) and recompile, the device never gets a random address.

  • Hi Olivia,

    Can you show me how you are calling these functions? Does GAP_ConfigDeviceAddr() return success after you call it in your broadcaster version? How are you checking these addresses? Are you using a sniffer to see the address and resetting/power cycling the device to see if the address ever changes?
  • Hi Jessica, 

    In summary, I have a peripheral application that runs perfectly. To convert this to a broadcaster I have changed the peripheral files to the broadcaster files. This version still works fine. However when I change the import location for the osal_icall_ble.c file from

    examples/simple_peripheral/cc26xx/stack/osal_icall_ble.c                         to                              examples/simple_broadcaster/cc26xx/stack/osal_icall_ble.c

    And update the build_config.opt from -DHOST_CONFIG=PERIPHERAL_CFG and -DBLE_V42_FEATURES=EXT_DATA_LEN_CFG to -DHOST_CONFIG=BROADCASTER_CFG then the application still works, but the GAP_ConfigDeviceAddr() function returns a value of 1 (a generic failure) when it executes: 

        // Send the message
        return sendWaitMatchCS(ICall_getEntityId(), msg,
                               matchGapConfigDeviceAddrCS);

    And therefore it doesn't update the device address. I have not changed any of the code between the working and non working versions with the exceptions of the changes listed above.

    This is the function which calls the address configuration function:

    static void simple_broadcaster_init(void) {
        // ******************************************************************
        // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
        // ******************************************************************
        // Register the current thread as an ICall dispatcher application
        // so that the application can send and receive messages.
        ICall_registerApp(&selfEntity, &sem);
    
        {
            // Hard code the BD Address till CC2650 board gets its own IEEE address
            uint8 bdAddress[B_ADDR_LEN] = {0x0f, 0x01, 0x02, 0x03, 0x04, 0x05};
            HCI_EXT_SetBDADDRCmd(bdAddress);
        }
    
    #ifdef USE_RCOSC
        RCOSC_enableCalibration();
    #endif  // USE_RCOSC
    
        // Create an RTOS queue for message from profile to be sent to app.
        appMsgQueue           = Util_constructQueue(&appMsg);
    
        // Setup the GAP Broadcaster Role Profile
        {
            // For all hardware platforms, device starts advertising upon initialization
            uint8_t initialAdvertEnable = FALSE;
    
            // By setting this to zero, the device will go into the waiting state after
            // being discoverable for 30.72 second, and will not being advertising again
            // until the enabler is set back to TRUE
            uint16_t advertOffTime = 0;
    
            // Set the GAP Role Parameters
            GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initialAdvertEnable);
            GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t), &advertOffTime);
    
            GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData);
            GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
        }
    
        // Set advertising interval
        {
            uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;  // same as "advertPeriod * 16"
    
            GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advInt);
            GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advInt);
            GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advInt);
            GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt);
        }
    
        // Start the Device
        VOID GAPRole_StartDevice(&BLEAdvBroadcaster_gapRoleCBs);
    
        // Setup the address mode to use a randomly generated address
        VOID GAP_ConfigDeviceAddr(ADDRMODE_STATIC, NULL);
    
        uint8_t enableAdvertising = TRUE;
        GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &enableAdvertising);
    }
    

    I have a sniffer to confirm what addresses are being produced and yes I am power cycling the device but for the broadcaster version the address never changes. Since the config device function fails, I always get {0x0f, 0x01, 0x02, 0x03, 0x04, 0x05} as the address, unless I remove those lines, in which case I get the PUBLIC address for the device which is not what I want. 

    Do you have any idea why changing the configuration of the stack would cause a generic failure in the configure device address function?

  • Hi Olivia,

    After comparing osal_icall_ble.c for each example, I saw that GAPBondMrg_Init() is not called in the broadcast version. After looking into this further, that makes sense because broadcasters by definition do not connect to other devices, they just advertise/broadcast. In order to have a resolvable address you would have to know it's IRK and CSRK which are only communicated when connected. As a result, you cannot have a random resolvable address when using broadcaster which is why it no longer gets generated when you replace the files.

  • Hi Jessica, 

    Thanks so much for looking into this. 

    I fully understand why broadcasters can't have Random Resolvable Addresses, but does the generation of a Static address also need an IRK/CSRK? I was under the impression that Static addresses are random but not resolvable. I ask since I only want a static address for my broadcaster and the documentation I've read has implied that only Non-resolvable/Resolvable private addresses need an IRK to generate them. So in theory the lack of IRK and CSRK shouldn't affect the generation of a STATIC address.

    See: https://www.bluetooth.com/specifications/bluetooth-core-specification pg 2556-2559

    Olivia

  • Olivia,

    I am looking into this further and will get back to you.
  • Hi Olivia,

    I wanted to check, you said you are using a CC2640R2 based device and yet are using the SimpleLink BLE v2.2.2 stack SDK. This SDK is not suppose to be compatible with the CC2640R2 so can you try running this using the CC2640R2 SDK?

  • Olivia,

    Also can you tell me what gets returned after you call GAP_ConfigDeviceAddr() in your code?
  • Hi Jessica, 

    I get a return value of 1 when I call GAP_ConfigDeviceAddr() and I may have mispoken about using the CC2640 earlier, I am actually using CC2650 which is supported by the BLE-Stack V2.2.2, 

    Best,

    Olivia

  • Hi Olivia,

    Can you try running it again and confirm you get a return value of 1 when calling GAP_ConfigDeviceAddr()? That function should not return a 1.
  • Hi Jessica, 

    I have run it again and attached a photo below. The function returns a value of 1 for me.

  • Hi Olivia,

    I'm guessing the compiler is optimizing something so you can't see that value. Can you try calling GAP_ConfigDeviceAddr from SimpleBLEObserver_processRoleEvent() under GAP_DEVICE_INIT_DONE_EVENT?
  • Hi Jessica, 

    I have run it again with an optimization level of 0 (Register Optimizations) and with the GAP_ConfigDeviceAddr() function within the GAP_DEVICE_INIT_DONE_EVENT case and it still returns a value of 1.

  • Hi Jessica,
    Are there any updates on this?
  • Hi Olivia,

    No there are no updates on this. I do not know how you are seeing a 1 as a return value when the function only returns
    SUCCESS (0x00),
    bleNotReady (0x10): GAP layer has not been started
    bleIncorrectMode (0x12): there is currently BLE activity, can not change address
    INVALIDPARAMETER (0x02): invalid address mode passed into function

    The only recommendation I can think of is starting with a clean Simple Broadcaster example and make the call to Gap_ConfigDeviceAddr(). If that works, you can try adding in your additional code. Without seeing your actual code it is hard for me to debug it. My guess is that if you are not seeing a random address then one of the other errors is getting returned which would could be a result of how you are converting your code to broadcaster.