Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
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

error in sd_ble_gap_addr_set function

I want to change the MAC before doing some advertising, they recommended using the ble_gap_addr_set function, but whenever I call the function I get an error and the application stops.

I've tried with several approaches, including the approaches mentioned in the link below, in this approach I get error code 8.

https://devzone.nordicsemi.com/f/nordic-q-a/37322/sd_ble_gap_addr_set-pm_id_addr_set-returns-nrf_success-but-chip-still-uses-default-address-in-sdk15

In the approach I'm going to attach here, I get error code 3202. I've already tried to stop advertising before executing the function, I've also tried to only start advertising after calling the function, but even before starting advertising, always when I call the sd_ble_gap_addr_set function I get the error.

2112.ble_app_blinky_c2.7z

I use nRF5 SDK 17.0.2, and Softdevice S140, based on blinky's central example!

The most relevant part of the code is below, could someone help me to solve this problem?

            if(newdisp && advertising[7] == 0x01 && advertising[8] != 0x00){

              ble_gap_addr_t my_addr;

              ret_code_t err_code;
              err_code = sd_ble_gap_adv_stop(m_adv_handle);
              memcpy(enderecoatual,endereco,sizeof(endereco));
              newdisp = 0;
              msg = 1;
              err_code = sd_ble_gap_addr_get(&my_addr);
              APP_ERROR_CHECK(err_code);
              my_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE;
              my_addr.addr[0] = p_scan_evt->params.p_not_found->peer_addr.addr[5];
              my_addr.addr[1] = p_scan_evt->params.p_not_found->peer_addr.addr[4];
              my_addr.addr[2] = p_scan_evt->params.p_not_found->peer_addr.addr[3];
              my_addr.addr[3] = p_scan_evt->params.p_not_found->peer_addr.addr[2];
              my_addr.addr[4] = p_scan_evt->params.p_not_found->peer_addr.addr[1];
              my_addr.addr[5] = p_scan_evt->params.p_not_found->peer_addr.addr[0];
              err_code = sd_ble_gap_addr_set(&my_addr);
              NRF_LOG_INFO("Erro: %x", err_code);
              APP_ERROR_CHECK(err_code);

             advertising_start();
            }

I tried to change the type of address, I tried to manually put a standardized address, anyway I've tried all the approaches I found on the forum, mostly always solved in previous SDK, but for this SDK 17.0.2 I'm not able to get around this error in the call sd_ble_gap_addr_set function.

Please, if you can take the time to apply solutions that really solve the code problem, I would be very grateful.

  • Hi,

    In the approach I'm going to attach here, I get error code 3202.

    Looking at the documentation for sd_ble_gap_addr_set(), we can see that BLE_ERROR_GAP_INVALID_BLE_ADDR (Invalid address) is 3202.

    So the address you are setting is not a valid address.

    For a Non-Resolvable Random Private Address, the two MSB of the random device address have to be 0b00

    BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 6, Part B page 2859

    See also e.g. this site.

  • Hello ,

    I've already tried this change, I've also tried to change the address type and reset it just before starting advertising as I mentioned, and this hasn't changed my problem at all.

    I can even reset all 46 bits to 0 and nothing changes.

    If I call the sd_ble_gap_addr_set function, even without changing any bit of the current address, it already gives the error.

  • Ah, I see it now, the doc also mentions "The address type must be either @ref BLE_GAP_ADDR_TYPE_PUBLIC or @ref BLE_GAP_ADDR_TYPE_RANDOM_STATIC"

    If you want to use a private address you should use sd_ble_gap_privacy_set

  • As I said I've already tested several approaches found on the forum, changing the address type one of these ways, I tried again and the result was as expected, it didn't resolve... I keep getting an error!

  • Problem solved, the problem is that when using the sd_ble_gap_addr_set function, in addition to interrupting advertising, the scan must also be interrupted before calling the function. After interrupting both before calling the function there were no more errors.

Related