Beispiel #1
0
uint32_t conn_mw_ble_gap_privacy_set(uint8_t const * const p_rx_buf,
                                     uint32_t              rx_buf_len,
                                     uint8_t * const       p_tx_buf,
                                     uint32_t * const      p_tx_buf_len)
{
    SER_ASSERT_NOT_NULL(p_rx_buf);
    SER_ASSERT_NOT_NULL(p_tx_buf);
    SER_ASSERT_NOT_NULL(p_tx_buf_len);

    uint32_t err_code = NRF_SUCCESS;
    uint32_t sd_err_code;

    ble_gap_privacy_params_t privacy_params;
    ble_gap_privacy_params_t * p_privacy_params = &privacy_params;

    ble_gap_irk_t irk;
    privacy_params.p_device_irk = &irk;

    err_code = ble_gap_privacy_set_req_dec(p_rx_buf, rx_buf_len, &p_privacy_params);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

    sd_err_code = sd_ble_gap_privacy_set(p_privacy_params);

    err_code = ble_gap_privacy_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

   return err_code;
}
Beispiel #2
0
ret_code_t im_privacy_set(pm_privacy_params_t const * p_privacy_params)
{
    #if (NRF_SD_BLE_API_VERSION == 2)

        ret_code_t     ret;
        ble_gap_addr_t privacy_addr;
        ble_gap_irk_t  current_irk;
        ble_opt_t      privacy_options;
        ble_opt_t      current_privacy_options;

        NRF_PM_DEBUG_CHECK(p_privacy_params != NULL);

        privacy_addr.addr_type                        = p_privacy_params->private_addr_type;
        privacy_options.gap_opt.privacy.p_irk         = p_privacy_params->p_device_irk;
        privacy_options.gap_opt.privacy.interval_s    = p_privacy_params->private_addr_cycle_s;
        current_privacy_options.gap_opt.privacy.p_irk = &current_irk;

        // Can not fail.
        (void) sd_ble_opt_get(BLE_GAP_OPT_PRIVACY, &current_privacy_options);
        (void) sd_ble_opt_set(BLE_GAP_OPT_PRIVACY, &privacy_options);

        if (p_privacy_params->privacy_mode == BLE_GAP_PRIVACY_MODE_OFF)
        {
            ret = address_set_v2(BLE_GAP_ADDR_CYCLE_MODE_NONE, &m_current_id_addr);
        }
        else
        {
            ret = address_set_v2(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &privacy_addr);
        }

        if (ret != NRF_SUCCESS)
        {
            // Restore previous settings.
            (void) sd_ble_opt_set(BLE_GAP_OPT_PRIVACY, &current_privacy_options);
        }

        // NRF_ERROR_BUSY,
        // NRF_ERROR_INVALID_STATE,
        // NRF_ERROR_INVALID_PARAM, if address type is not valid.
        return ret;

    #else

        return sd_ble_gap_privacy_set(p_privacy_params);

    #endif
}