KW40Z runtime change Bluetooth MAC address gBDAddress_c

cancel
Showing results for 
Search instead for 
Did you mean: 

KW40Z runtime change Bluetooth MAC address gBDAddress_c

Jump to solution
530 Views
lucianfiran
Contributor V

IAR 7.50;  KW40Z_Connectivity_Software_1.0.1 (KSDK_1.3.0)

As the Bluetooth stack comes pre-compiled a variable interface is gBDAddress_c.

How to change at runtime this address ?

KW40Z_Connectivity_Software_1.0.1\ConnSw\examples\bluetooth\common\ble_controller_task.c

/* Public Device Address */
const uint8_t gBDAddress_c[6] = {BD_ADDR};


app_preinclude.h

#define BD_ADDR             0x13,0x00,0x00,0x9F,0x04,0x00

I find it easy to change the definition by removing the const part, is it ok ?

Other ways that I can think of is some volatile keyword added ?

What is the solution as this definition may have an external counterpart linked in host stack.

1 Solution
138 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Lucian

You can change it if you remove the const type qualifier, but the BD address is used when scanning/advertising, initiating connections, when performing the BLE pairing using SMP, the BDADDR is used internally to confirm identity, etc. So it must not be changed in runtime this BD_ADDRS. Normally in a use case, in your application you set the BD_ADDRS, and you keep that address for the all the BLE application. Note: if you reset the device and this address is random generated, it remain the same logic, you only set it once and it doesn't change.


Hope this information helps you
Have a great day,
Jorge Alcala

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

4 Replies
139 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Lucian

You can change it if you remove the const type qualifier, but the BD address is used when scanning/advertising, initiating connections, when performing the BLE pairing using SMP, the BDADDR is used internally to confirm identity, etc. So it must not be changed in runtime this BD_ADDRS. Normally in a use case, in your application you set the BD_ADDRS, and you keep that address for the all the BLE application. Note: if you reset the device and this address is random generated, it remain the same logic, you only set it once and it doesn't change.


Hope this information helps you
Have a great day,
Jorge Alcala

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

138 Views
lucianfiran
Contributor V

So I can change the BLE MAC address inside hardware_init ?

ApplMain.c

....
void main_task(uint32_t param)
{
    ....

    hardware_init();

    ....
        /* Initialize peripheral drivers specific to the application */
        BleApp_Init();
      
        /* BLE Radio Init */    
        XcvrInit(BLE); 

...

0 Kudos
138 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Lucian

Yes, before any connection and it shouldn't change. Or you could change it in the macro define #define BD_ADDR


Hope this information helps you
Have a great day,
Jorge Alcala

138 Views
lucianfiran
Contributor V

This variable is most likely exported in the host stack ble_controller_lib.a

pastedImage_4.png

Changing is type can lead to unwanted unpredictable behaviour ?

0 Kudos