summaryrefslogtreecommitdiff
path: root/implementation/e2e_protection/src/e2e
diff options
context:
space:
mode:
Diffstat (limited to 'implementation/e2e_protection/src/e2e')
-rw-r--r--implementation/e2e_protection/src/e2e/profile/e2e_provider_impl.cpp120
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp8
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp5
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile04/checker.cpp114
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile04/profile_04.cpp33
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile04/protector.cpp81
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp9
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp5
8 files changed, 336 insertions, 39 deletions
diff --git a/implementation/e2e_protection/src/e2e/profile/e2e_provider_impl.cpp b/implementation/e2e_protection/src/e2e/profile/e2e_provider_impl.cpp
index 7a82446..111e126 100644
--- a/implementation/e2e_protection/src/e2e/profile/e2e_provider_impl.cpp
+++ b/implementation/e2e_protection/src/e2e/profile/e2e_provider_impl.cpp
@@ -3,33 +3,49 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#include <iomanip>
+#include <sstream>
+
+#include <vsomeip/internal/logger.hpp>
+
#include "../../../../e2e_protection/include/e2e/profile/e2e_provider_impl.hpp"
#include "../../../../e2e_protection/include/e2e/profile/profile01/checker.hpp"
#include "../../../../e2e_protection/include/e2e/profile/profile01/profile_01.hpp"
#include "../../../../e2e_protection/include/e2e/profile/profile01/protector.hpp"
+#include "../../../../e2e_protection/include/e2e/profile/profile04/checker.hpp"
+#include "../../../../e2e_protection/include/e2e/profile/profile04/profile_04.hpp"
+#include "../../../../e2e_protection/include/e2e/profile/profile04/protector.hpp"
+
#include "../../../../e2e_protection/include/e2e/profile/profile_custom/checker.hpp"
#include "../../../../e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp"
#include "../../../../e2e_protection/include/e2e/profile/profile_custom/protector.hpp"
-#include <sstream>
-
namespace {
template<typename value_t>
-value_t read_value_from_config(const std::shared_ptr<vsomeip_v3::cfg::e2e>& config,
- const std::string& name,
- value_t default_value = value_t()) {
- if(config && config->custom_parameters.count(name)) {
- value_t value;
+value_t read_value_from_config(const std::shared_ptr<vsomeip_v3::cfg::e2e> &_config,
+ const std::string &_name,
+ value_t _default_value = value_t()) {
+
+ if (_config && _config->custom_parameters.count(_name)) {
+
std::stringstream its_converter;
- its_converter << config->custom_parameters[name];
- its_converter >> value;
- return value;
+ std::string its_value(_config->custom_parameters[_name]);
+
+ if (its_value.size() > 1 && its_value[0] == '0' && its_value[1] == 'x') {
+ its_converter << std::hex << its_value;
+ } else {
+ its_converter << std::dec << its_value;
+ }
+
+ value_t its_converted_value;
+ its_converter >> its_converted_value;
+ return its_converted_value;
}
- return default_value;
+ return _default_value;
}
} // namespace
@@ -51,67 +67,109 @@ e2e_provider_impl::~e2e_provider_impl()
bool e2e_provider_impl::add_configuration(std::shared_ptr<cfg::e2e> config)
{
- if(config->profile == "CRC8") {
+ if (config->profile == "CRC8" || config->profile == "P01") {
process_e2e_profile<profile01::profile_config, profile01::profile_01_checker, profile01::protector>(config);
return true;
}
- if(config->profile == "CRC32") {
+ if (config->profile == "CRC32" || config->profile == "CSTM") {
process_e2e_profile<profile_custom::profile_config, profile_custom::profile_custom_checker, profile_custom::protector>(config);
return true;
}
+ if (config->profile == "P04") {
+ process_e2e_profile<profile04::profile_config, profile04::profile_04_checker, profile04::protector>(config);
+ return true;
+ }
+
return false;
}
bool e2e_provider_impl::is_protected(e2exf::data_identifier_t id) const
{
- return custom_protectors.count(id) > 0;
+ return custom_protectors_.count(id) > 0;
}
bool e2e_provider_impl::is_checked(e2exf::data_identifier_t id) const
{
- return custom_checkers.count(id) > 0;
+ return custom_checkers_.count(id) > 0;
+}
+
+std::size_t e2e_provider_impl::get_protection_base(e2exf::data_identifier_t id) const
+{
+ const auto found_base = custom_bases_.find(id);
+ if (found_base != custom_bases_.end())
+ return (found_base->second);
+
+ return (0);
}
-void e2e_provider_impl::protect(e2exf::data_identifier_t id, e2e_buffer &_buffer)
+void e2e_provider_impl::protect(e2exf::data_identifier_t id, e2e_buffer &_buffer,
+ instance_t _instance)
{
- auto protector = custom_protectors.find(id);
- if(protector != custom_protectors.end()) {
- protector->second->protect(_buffer);
+ auto protector = custom_protectors_.find(id);
+ if(protector != custom_protectors_.end()) {
+ protector->second->protect(_buffer, _instance);
}
}
-void e2e_provider_impl::check(e2exf::data_identifier_t id, const e2e_buffer &_buffer,
- profile_interface::check_status_t &_generic_check_status)
+void e2e_provider_impl::check(e2exf::data_identifier_t id,
+ const e2e_buffer &_buffer, instance_t _instance,
+ profile_interface::check_status_t &_generic_check_status)
{
- auto checker = custom_checkers.find(id);
- if(checker != custom_checkers.end()) {
- checker->second->check(_buffer, _generic_check_status);
+ auto checker = custom_checkers_.find(id);
+ if(checker != custom_checkers_.end()) {
+ checker->second->check(_buffer, _instance, _generic_check_status);
}
}
template<>
vsomeip_v3::e2e::profile01::profile_config
-e2e_provider_impl::make_e2e_profile_config(const std::shared_ptr<cfg::e2e>& config) {
- uint16_t crc_offset = read_value_from_config<uint16_t>(config, "crc_offset");
- uint16_t data_length = read_value_from_config<uint16_t>(config, "data_length");
+e2e_provider_impl::make_e2e_profile_config(const std::shared_ptr<cfg::e2e> &_config) {
+ uint16_t data_id = read_value_from_config<uint16_t>(_config, "data_id");
+ uint16_t crc_offset = read_value_from_config<uint16_t>(_config, "crc_offset");
+ uint16_t data_length = read_value_from_config<uint16_t>(_config, "data_length");
// counter field behind CRC8
- uint16_t counter_offset = read_value_from_config<uint16_t>(config, "counter_offset", 8);
+ uint16_t counter_offset = read_value_from_config<uint16_t>(_config, "counter_offset", 8);
// data id nibble behind 4 bit counter value
- uint16_t data_id_nibble_offset = read_value_from_config<uint16_t>(config, "data_id_nibble_offset", 12);
+ uint16_t data_id_nibble_offset = read_value_from_config<uint16_t>(_config, "data_id_nibble_offset", 12);
e2e::profile01::p01_data_id_mode data_id_mode =
static_cast<e2e::profile01::p01_data_id_mode>(
- read_value_from_config<uint16_t>(config, "data_id_mode"));
+ read_value_from_config<uint16_t>(_config, "data_id_mode"));
- return e2e::profile01::profile_config(crc_offset, config->data_id, data_id_mode,
+ return e2e::profile01::profile_config(crc_offset, data_id, data_id_mode,
data_length, counter_offset, data_id_nibble_offset);
}
template<>
+vsomeip_v3::e2e::profile04::profile_config
+e2e_provider_impl::make_e2e_profile_config(const std::shared_ptr<cfg::e2e> &_config) {
+
+ uint32_t data_id = read_value_from_config<uint32_t>(_config, "data_id");
+
+ size_t offset = read_value_from_config<size_t>(_config, "crc_offset");
+ if (offset % 8)
+ VSOMEIP_ERROR << "Offset in E2E P04 configuration must be multiple of 8"
+ " (" << offset << ")";
+ offset /= 8;
+
+ size_t min_data_length = read_value_from_config<size_t>(_config,
+ "min_data_length", 0);
+
+ size_t max_data_length = read_value_from_config<size_t>(_config,
+ "max_data_length", size_t(0xffff));
+
+ uint16_t max_delta_counter = read_value_from_config<uint16_t>(_config,
+ "max_delta_counter", uint16_t(0xffff));
+
+ return e2e::profile04::profile_config(data_id, offset,
+ min_data_length, max_data_length, max_delta_counter);
+}
+
+template<>
e2e::profile_custom::profile_config
e2e_provider_impl::make_e2e_profile_config(const std::shared_ptr<cfg::e2e>& config) {
uint16_t crc_offset = read_value_from_config<uint16_t>(config, "crc_offset");
diff --git a/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp b/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp
index bea8dc1..a5d75d8 100644
--- a/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp
+++ b/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp
@@ -16,8 +16,11 @@ namespace e2e {
namespace profile01 {
// [SWS_E2E_00196]
-void profile_01_checker::check(const e2e_buffer &_buffer,
- e2e::profile_interface::check_status_t &_generic_check_status) {
+void profile_01_checker::check(const e2e_buffer &_buffer, instance_t _instance,
+ e2e::profile_interface::check_status_t &_generic_check_status) {
+
+ (void)_instance;
+
std::lock_guard<std::mutex> lock(check_mutex_);
_generic_check_status = e2e::profile_interface::generic_check_status::E2E_ERROR;
@@ -34,7 +37,6 @@ void profile_01_checker::check(const e2e_buffer &_buffer,
<< (uint32_t) calculated_crc << " received CRC: " << (uint32_t) received_crc;
}
}
- return;
}
} // namespace profile01
diff --git a/implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp b/implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp
index 551a801..e5cb4ba 100644
--- a/implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp
+++ b/implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp
@@ -16,7 +16,10 @@ namespace e2e {
namespace profile01 {
/** @req [SWS_E2E_00195] */
-void protector::protect(e2e_buffer &_buffer) {
+void protector::protect(e2e_buffer &_buffer, instance_t _instance) {
+
+ (void)_instance;
+
std::lock_guard<std::mutex> lock(protect_mutex_);
if (profile_01::is_buffer_length_valid(config_, _buffer)) {
diff --git a/implementation/e2e_protection/src/e2e/profile/profile04/checker.cpp b/implementation/e2e_protection/src/e2e/profile/profile04/checker.cpp
new file mode 100644
index 0000000..c9761ca
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile04/checker.cpp
@@ -0,0 +1,114 @@
+// Copyright (C) 2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <iomanip>
+
+#include <vsomeip/internal/logger.hpp>
+#include "../../utility/include/byteorder.hpp"
+
+#include "../../../../../e2e_protection/include/e2e/profile/profile04/checker.hpp"
+
+
+namespace vsomeip_v3 {
+namespace e2e {
+namespace profile04 {
+
+// [SWS_E2E_00355]
+void profile_04_checker::check(const e2e_buffer &_buffer, instance_t _instance,
+ e2e::profile_interface::check_status_t &_generic_check_status) {
+
+ std::lock_guard<std::mutex> lock(check_mutex_);
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_ERROR;
+
+ if (_instance > VSOMEIP_E2E_PROFILE04_MAX_INSTANCE) {
+ VSOMEIP_ERROR << "E2E Profile 4 can only be used for instances [1-255]";
+ return;
+ }
+
+ /** @req [SWS_E2E_356] */
+ if (verify_input(_buffer)) {
+ /** @req [SWS_E2E_357] */
+ uint16_t its_received_length;
+ if (read_16(_buffer, its_received_length, 0)) {
+ /** @req [SWS_E2E_358] */
+ uint16_t its_received_counter;
+ if (read_16(_buffer, its_received_counter, 2)) {
+ /** @req [SWS_E2E_359] */
+ uint32_t its_received_data_id;
+ if (read_32(_buffer, its_received_data_id, 4)) {
+ /** @req [SWS_E2E_360] */
+ uint32_t its_received_crc;
+ if (read_32(_buffer, its_received_crc, 8)) {
+ uint32_t its_crc = profile_04::compute_crc(config_, _buffer);
+ /** @req [SWS_E2E_361] */
+ if (its_received_crc != its_crc) {
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_WRONG_CRC;
+ VSOMEIP_ERROR << std::hex << "E2E P04 protection: CRC32 does not match: calculated CRC: "
+ << its_crc << " received CRC: " << its_received_crc;
+ } else {
+ uint32_t its_data_id(uint32_t(_instance) << 24 | config_.data_id_);
+ if (its_received_data_id == its_data_id
+ && static_cast<size_t>(its_received_length) == _buffer.size()
+ && verify_counter(its_received_counter)) {
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_OK;
+ }
+ counter_ = its_received_counter;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+bool
+profile_04_checker::verify_input(const e2e_buffer &_buffer) const {
+
+ auto its_length = _buffer.size();
+ return (its_length >= config_.min_data_length_
+ && its_length <= config_.max_data_length_);
+}
+
+bool
+profile_04_checker::verify_counter(uint16_t _received_counter) const {
+
+ static bool has_counter(false);
+ uint16_t its_delta(0);
+
+ if (has_counter) {
+ if (counter_ < _received_counter)
+ its_delta = uint16_t(_received_counter - counter_);
+ else
+ its_delta = uint16_t(uint16_t(0xffff) - counter_ + _received_counter);
+ } else {
+ has_counter = true;
+ }
+
+ return (its_delta <= config_.max_delta_counter_);
+}
+
+bool
+profile_04_checker::read_16(const e2e_buffer &_buffer,
+ uint16_t &_data, size_t _index) const {
+
+ _data = VSOMEIP_BYTES_TO_WORD(_buffer[config_.offset_ + _index],
+ _buffer[config_.offset_ + _index + 1]);
+ return (true);
+}
+
+bool
+profile_04_checker::read_32(const e2e_buffer &_buffer,
+ uint32_t &_data, size_t _index) const {
+
+ _data = VSOMEIP_BYTES_TO_LONG(_buffer[config_.offset_ + _index],
+ _buffer[config_.offset_ + _index + 1],
+ _buffer[config_.offset_ + _index + 2],
+ _buffer[config_.offset_ + _index + 3]);
+ return (true);
+}
+
+} // namespace profile01
+} // namespace e2e
+} // namespace vsomeip_v3
diff --git a/implementation/e2e_protection/src/e2e/profile/profile04/profile_04.cpp b/implementation/e2e_protection/src/e2e/profile/profile04/profile_04.cpp
new file mode 100644
index 0000000..05ab5e9
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile04/profile_04.cpp
@@ -0,0 +1,33 @@
+// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "../../../../../e2e_protection/include/e2e/profile/profile04/profile_04.hpp"
+#include "../../../../../e2e_protection/include/crc/crc.hpp"
+
+namespace vsomeip_v3 {
+namespace e2e {
+namespace profile04 {
+
+uint32_t profile_04::compute_crc(const profile_config &_config, const e2e_buffer &_buffer) {
+
+ buffer_view its_before(_buffer, _config.offset_ + 8);
+ uint32_t computed_crc = e2e_crc::calculate_profile_04(its_before);
+
+ if (_config.offset_ + 12 < _buffer.size()) {
+ buffer_view its_after(_buffer, _config.offset_ + 12, _buffer.size());
+ computed_crc = e2e_crc::calculate_profile_04(its_after, computed_crc);
+ }
+
+ return (computed_crc);
+}
+
+} // namespace profile04
+} // namespace e2e
+} // namespace vsomeip_v3
diff --git a/implementation/e2e_protection/src/e2e/profile/profile04/protector.cpp b/implementation/e2e_protection/src/e2e/profile/profile04/protector.cpp
new file mode 100644
index 0000000..a9287f2
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile04/protector.cpp
@@ -0,0 +1,81 @@
+// Copyright (C) 2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <iomanip>
+
+#include "../../../../../e2e_protection/include/e2e/profile/profile04/protector.hpp"
+
+#include <vsomeip/internal/logger.hpp>
+#include "../../utility/include/byteorder.hpp"
+
+namespace vsomeip_v3 {
+namespace e2e {
+namespace profile04 {
+
+/** @req [SWS_E2E_00195] */
+void
+protector::protect(e2e_buffer &_buffer, instance_t _instance) {
+ std::lock_guard<std::mutex> lock(protect_mutex_);
+
+ if (_instance > VSOMEIP_E2E_PROFILE04_MAX_INSTANCE) {
+ VSOMEIP_ERROR << "E2E Profile 4 can only be used for instances [1-255]";
+ return;
+ }
+
+ /** @req: [SWS_E2E_00363] */
+ if (verify_inputs(_buffer)) {
+
+ /** @req [SWS_E2E_00364] */
+ write_16(_buffer, static_cast<uint16_t>(_buffer.size()), 0);
+
+ /** @req [SWS_E2E_00365] */
+ write_16(_buffer, counter_, 2);
+
+ /** @req [SWS_E2E_00366] */
+ uint32_t its_data_id(uint32_t(_instance) << 24 | config_.data_id_);
+ write_32(_buffer, its_data_id, 4);
+
+ /** @req [SWS_E2E_00367] */
+ uint32_t its_crc = profile_04::compute_crc(config_, _buffer);
+
+ /** @req [SWS_E2E_0368] */
+ write_32(_buffer, its_crc, 8);
+
+ /** @req [SWS_E2E_00369] */
+ increment_counter();
+ }
+}
+
+bool
+protector::verify_inputs(e2e_buffer &_buffer) {
+
+ return (_buffer.size() >= config_.min_data_length_
+ && _buffer.size() <= config_.max_data_length_);
+}
+
+void
+protector::write_16(e2e_buffer &_buffer, uint16_t _data, size_t _index) {
+
+ _buffer[config_.offset_ + _index] = VSOMEIP_WORD_BYTE1(_data);
+ _buffer[config_.offset_ + _index + 1] = VSOMEIP_WORD_BYTE0(_data);
+}
+
+void
+protector::write_32(e2e_buffer &_buffer, uint32_t _data, size_t _index) {
+
+ _buffer[config_.offset_ + _index] = VSOMEIP_LONG_BYTE3(_data);
+ _buffer[config_.offset_ + _index + 1] = VSOMEIP_LONG_BYTE2(_data);
+ _buffer[config_.offset_ + _index + 2] = VSOMEIP_LONG_BYTE1(_data);
+ _buffer[config_.offset_ + _index + 3] = VSOMEIP_LONG_BYTE0(_data);
+}
+
+void
+protector::increment_counter() {
+ counter_++;
+}
+
+} // namespace profile04
+} // namespace e2e
+} // namespace vsomeip_v3
diff --git a/implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp b/implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp
index 42e1ca8..9916a2f 100644
--- a/implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp
+++ b/implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp
@@ -16,11 +16,15 @@ namespace e2e {
namespace profile_custom {
void profile_custom_checker::check(const e2e_buffer &_buffer,
- e2e::profile_interface::check_status_t &_generic_check_status) {
+ instance_t _instance,
+ e2e::profile_interface::check_status_t &_generic_check_status) {
+
+ (void)_instance;
+
std::lock_guard<std::mutex> lock(check_mutex_);
_generic_check_status = e2e::profile_interface::generic_check_status::E2E_ERROR;
- if (profile_custom::is_buffer_length_valid(config_, _buffer)) {
+ if (profile_custom::is_buffer_length_valid(config_, _buffer)) {
uint32_t received_crc(0);
uint32_t calculated_crc(0);
@@ -34,7 +38,6 @@ void profile_custom_checker::check(const e2e_buffer &_buffer,
<< (uint32_t) calculated_crc << " received CRC: " << (uint32_t) received_crc;
}
}
- return;
}
uint32_t profile_custom_checker::read_crc(const e2e_buffer &_buffer) const {
diff --git a/implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp b/implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp
index 276c02b..c71f91f 100644
--- a/implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp
+++ b/implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp
@@ -16,7 +16,10 @@ namespace vsomeip_v3 {
namespace e2e {
namespace profile_custom {
-void protector::protect(e2e_buffer &_buffer) {
+void protector::protect(e2e_buffer &_buffer, instance_t _instance) {
+
+ (void)_instance;
+
std::lock_guard<std::mutex> lock(protect_mutex_);
if (profile_custom::is_buffer_length_valid(config_, _buffer)) {