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
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MAC address type decoder

Hi

I found the function

/**@brief Function for decoding the BLE address type.
 *
 * @param[in] p_addr 	The BLE address.
 *
 * @return    			Address type, or an error if the address type is incorrect, that is it does not match @ref BLE_GAP_ADDR_TYPES.
 *
 */
static uint16_t nrf_ble_scan_address_type_decode(uint8_t const * p_addr)
{
    uint8_t addr_type = p_addr[0];

    // See Bluetooth Core Specification Vol 6, Part B, section 1.3.
    addr_type  = addr_type >> 6;
    addr_type &= 0x03;

    // Check address type.
    switch (addr_type)
    {
        case 0:
        {
            return BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE;
        }

        case 1:
        {
            return BLE_GAP_ADDR_TYPE_PUBLIC;
        }

        case 2:
        {
            return BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
        }

        case 3:
        {
            return BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
        }

        default:
        {
            return BLE_ERROR_GAP_INVALID_BLE_ADDR;
        }
    }
}

in nrf_ble_scan.c.

This decoding looks wrong to me since https://devzone.nordicsemi.com/f/nordic-q-a/27012/how-to-distinguish-between-random-and-public-gap-addresses and Bluetooth Core specification Vol. 6 Part B, section 1.3. states that a resolvable private address has the MSB = 0. Though decoder above returns BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE if the MSB is 1 and the next bit = 0 (decimal 2).

Also the spec does not state that a public address has the MSB = 0 and the next bit = 1 (decimal 1).

A more correct version would return BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE for case 1. Also it should not check the MSB for PUBLIC addresses.

Or do I miss something?

Best regards

Parents Reply Children
No Data
Related