コード例 #1
0
ファイル: conn_mw_ble.c プロジェクト: HorseMa/BLE2ETHERNET
uint32_t conn_mw_ble_opt_get(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   opt_id;
    ble_opt_t  opt;
    ble_opt_t *p_opt = &opt;

    uint32_t err_code = NRF_SUCCESS;
    uint32_t sd_err_code;

    err_code = ble_opt_get_req_dec(p_rx_buf, rx_buf_len, &opt_id, &p_opt);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

    sd_err_code = sd_ble_opt_get(opt_id, p_opt);

    err_code = ble_opt_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, opt_id, p_opt);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

    return err_code;
}
コード例 #2
0
ファイル: id_manager.c プロジェクト: lyncxy119/Sentry
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
}
コード例 #3
0
ファイル: id_manager.c プロジェクト: lyncxy119/Sentry
ret_code_t im_privacy_get(pm_privacy_params_t * p_privacy_params)
{
    #if (NRF_SD_BLE_API_VERSION == 2)

        ble_gap_addr_t cur_addr;
        ble_opt_t      cur_privacy_opt;

        NRF_PM_DEBUG_CHECK(p_privacy_params               != NULL);
        NRF_PM_DEBUG_CHECK(p_privacy_params->p_device_irk != NULL);

        cur_privacy_opt.gap_opt.privacy.p_irk = p_privacy_params->p_device_irk;

        // Can not fail.
        (void) sd_ble_gap_address_get(&cur_addr);

        if (   cur_addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE
            || cur_addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE)
        {
            p_privacy_params->privacy_mode      = BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY;
            p_privacy_params->private_addr_type = cur_addr.addr_type;
        }
        else
        {
            p_privacy_params->privacy_mode = BLE_GAP_PRIVACY_MODE_OFF;
        }

        // Can not fail.
        (void) sd_ble_opt_get(BLE_GAP_OPT_PRIVACY, &cur_privacy_opt);

        p_privacy_params->private_addr_cycle_s = cur_privacy_opt.gap_opt.privacy.interval_s;

        return NRF_SUCCESS;

    #else

        return sd_ble_gap_privacy_get(p_privacy_params);

    #endif
}