Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Ble advertise custom MAC address does not chance the last 2 MSB

Hi guys,

I have custom MAC address that saved in the flash. I used the sd_ble_gap_address_set function to change the Mac address to my custom address.. I found out in phone that the Mac address that advertise is the same on the (MSB) part. The 2 MSB bits should change to 11xx. example if I have custom MSB byte of A7 the BLE advetsing MAC address should be E7 as per specification.

I might be missing something but please please help my ignorance.

Thank you.

Parents
  • Hi,

    The custom MAC address will be whatever you set it to with sd_ble_gap_address_set. The 2 MSB bit will not be set to 11 automatically when you are overriding the "default" MAC with your custom MAC.

    If you need the 2 MSB bit to be ‘11’, then you need to set this yourself.

    Note that if you have set the addr_type to BLE_GAP_ADDR_TYPE_RANDOM_STATIC, the sd_ble_gap_address_set function will return BLE_ERROR_GAP_INVALID_BLE_ADDR if the 2 MSB bit are not ‘11’.

     

        ble_gap_addr_t m_my_addr;
        m_my_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
        m_my_addr.addr[0] = 0xAA;
        m_my_addr.addr[1] = 0xBB; 
        m_my_addr.addr[2] = 0xCC;
        m_my_addr.addr[3] = 0xDD;
        m_my_addr.addr[4] = 0xEE;
        m_my_addr.addr[5] = 0x00;
        
        /* Set 2 MSBit to '11 */
        m_my_addr.addr[5] |= 0xC0; // 2 MSBit must be '11' for RANDOM_STATIC address.

Reply
  • Hi,

    The custom MAC address will be whatever you set it to with sd_ble_gap_address_set. The 2 MSB bit will not be set to 11 automatically when you are overriding the "default" MAC with your custom MAC.

    If you need the 2 MSB bit to be ‘11’, then you need to set this yourself.

    Note that if you have set the addr_type to BLE_GAP_ADDR_TYPE_RANDOM_STATIC, the sd_ble_gap_address_set function will return BLE_ERROR_GAP_INVALID_BLE_ADDR if the 2 MSB bit are not ‘11’.

     

        ble_gap_addr_t m_my_addr;
        m_my_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
        m_my_addr.addr[0] = 0xAA;
        m_my_addr.addr[1] = 0xBB; 
        m_my_addr.addr[2] = 0xCC;
        m_my_addr.addr[3] = 0xDD;
        m_my_addr.addr[4] = 0xEE;
        m_my_addr.addr[5] = 0x00;
        
        /* Set 2 MSBit to '11 */
        m_my_addr.addr[5] |= 0xC0; // 2 MSBit must be '11' for RANDOM_STATIC address.

Children
Related