コード例 #1
0
uint32_t sd_ble_gap_sec_params_reply(adapter_t *adapter, uint16_t conn_handle, uint8_t sec_status,
                                     ble_gap_sec_params_t const *p_sec_params,
                                     ble_gap_sec_keyset_t const *p_sec_keyset)
{
    encode_function_t encode_function = [&](uint8_t *buffer, uint32_t *length) -> uint32_t {
        uint32_t index = 0;
        auto err_code  = app_ble_gap_sec_keys_storage_create(conn_handle, &index);

        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }

        if (p_sec_keyset)
        {
            err_code = app_ble_gap_sec_keys_update(index, p_sec_keyset);

            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }

        return ble_gap_sec_params_reply_req_enc(conn_handle, sec_status, p_sec_params, p_sec_keyset,
                                                buffer, length);
    };

    decode_function_t decode_function = [&](uint8_t *buffer, uint32_t length,
                                            uint32_t *result) -> uint32_t {
        return ble_gap_sec_params_reply_rsp_dec(buffer, length, p_sec_keyset, result);
    };

    return gap_encode_decode(adapter, encode_function, decode_function);
}
コード例 #2
0
ファイル: app_mw_ble_gap.c プロジェクト: BLEHexapod/nrf_sdk
/**@brief Command response callback function for @ref sd_ble_gap_sec_params_reply BLE command.
 *
 * Callback for decoding the command response return code.
 *
 * @param[in] p_buffer  Pointer to begin of command response buffer.
 * @param[in] length    Length of data in bytes.
 *
 * @return Decoded command response return code.
 */
static uint32_t gap_sec_params_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
    uint32_t result_code   = 0;

    uint32_t err_code = ble_gap_sec_params_reply_rsp_dec(p_buffer, length,
                            m_output_params.gap_sec_params_reply_out_params.p_sec_keyset, &result_code);
    APP_ERROR_CHECK(err_code);

    // If soft device returned error free security context
    if (result_code)
    {
        err_code = app_ble_gap_sec_context_destroy(m_output_params.gap_sec_params_reply_out_params.conn_handle);
        SER_ASSERT(err_code == NRF_SUCCESS, err_code);
    }

    return result_code;
}