This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

sd_ble_gap_addr_get() shows different MAC address in the different example.

Hi, all.

I used sd_ble_gap_addr_get() function to get a MAC address in the different example and the result was different.

I tested this example in SDK v14.2 and v15.0 but I just got the same symptoms in both SDK.

1. /examples/ble_peripheral/ble_app_beacon

You can modify main() function. Red colored is additional code to test.

int main(void)
{
  static ble_gap_addr_t mac_addr;
  uint32_t err_code;

  // Initialize.
  log_init();
  timers_init();
  leds_init();
  power_management_init();
  ble_stack_init();
  advertising_init();

  // Start execution.
  NRF_LOG_INFO("Beacon example started.");
  advertising_start();

  err_code = sd_ble_gap_addr_get(&mac_addr);
  NRF_LOG_INFO("MAC_ADDR: %x:%x:%x:%x:%x:%x\r\n", mac_addr.addr[5], mac_addr.addr[4], mac_addr.addr[3], mac_addr.addr[2], mac_addr.addr[1], mac_addr.addr[0]);

  // Enter main loop.
  for (;; )
  {
    idle_state_handle();
  }

}

With my PCA10040 board, it shows C4:EA:D2:82:33:xx in UART log window. (I hid last bytes) 

2. /examples/iot/coap/ipv6/client

You can modify main() function. Red colored is additional code to test.

int main(void)
{

  uint32_t err_code;
  static ble_gap_addr_t mac_addr;
....

....

....

  // Start execution
  connectable_mode_enter();

  err_code = sd_ble_gap_addr_get(&mac_addr);
  APPL_LOG("MAC_ADDR: %x:%x:%x:%x:%x:%x\r\n", mac_addr.addr[5], mac_addr.addr[4], mac_addr.addr[3], mac_addr.addr[2], mac_addr.addr[1], mac_addr.addr[0]);

  // Enter main loop
  for (;;)
  {
    app_sched_execute();

    if (NRF_LOG_PROCESS() == false)
    {
      // Sleep waiting for an application event.
      err_code = sd_app_evt_wait();
      APP_ERROR_CHECK(err_code);
    }

  }
}

With my PCA10040 board, it shows 0:EA:D2:82:33:xx in UART log window. (I hid last bytes) 

As you know, the first byte value is different.

Which is a right MAC address ? I am very confused.

If you know any other good function to get a MAC address, let me know it.

Thanks.

Parents
  • Hi,

    The address might be set to a different address type, or use different values in some of the examples. See this post about how different address types are differentiated.

    Note that the address is not a true unique MAC address, it can be set to whatever you want. Normally the address is set from random numbers stored in FICR during production of the chip.

    Best regards,
    Jørgen

  • I understood your description. But I just wanted to know why first byte of MAC address has changed.

    I tested other examples and found that all examples related IoT shows MAC address starting 0x00.

    I think that config_medium_init() function of SDK_root/component/iot/socket/config/medium/config_medium.c is the cause of this symptom.

    This code replace first byte of MAC address (index 5 of ble_gap_addr_t structure) to 0x00.

    And ipv6_medium_eui48_set() in the code writes down changed MAC address to device.

    Would you explain why the process is required for IoT examples ?

    Best regards,

    Mike.

Reply
  • I understood your description. But I just wanted to know why first byte of MAC address has changed.

    I tested other examples and found that all examples related IoT shows MAC address starting 0x00.

    I think that config_medium_init() function of SDK_root/component/iot/socket/config/medium/config_medium.c is the cause of this symptom.

    This code replace first byte of MAC address (index 5 of ble_gap_addr_t structure) to 0x00.

    And ipv6_medium_eui48_set() in the code writes down changed MAC address to device.

    Would you explain why the process is required for IoT examples ?

    Best regards,

    Mike.

Children
No Data
Related