summaryrefslogtreecommitdiff
path: root/implementation/e2e_protection/src
diff options
context:
space:
mode:
Diffstat (limited to 'implementation/e2e_protection/src')
-rw-r--r--implementation/e2e_protection/src/crc/crc.cpp72
-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
9 files changed, 373 insertions, 74 deletions
diff --git a/implementation/e2e_protection/src/crc/crc.cpp b/implementation/e2e_protection/src/crc/crc.cpp
index 335b48d..60ddb6c 100644
--- a/implementation/e2e_protection/src/crc/crc.cpp
+++ b/implementation/e2e_protection/src/crc/crc.cpp
@@ -72,46 +72,48 @@ const uint8_t e2e_crc::lookup_table_profile_01_[256] = {
* - ReflectOut = true
*/
uint32_t e2e_crc::calculate_profile_04(buffer_view _buffer_view, const uint32_t _start_value) {
- uint32_t crc = _start_value ^ 0xFFFFFFFFU;
- for (uint8_t byte : _buffer_view) {
- crc = lookup_table_profile_04_[static_cast<uint8_t>(byte ^ crc)] ^ (crc >> 8U);
- }
- crc = crc ^ 0xFFFFFFFFU;
+ uint32_t crc = (_start_value ^ 0xFFFFFFFFU);
- return crc;
+ for (uint8_t byte : _buffer_view)
+ crc = lookup_table_profile_04_[static_cast<uint8_t>(byte ^ crc)] ^ (crc >> 8U);
+
+ return (crc ^ 0xFFFFFFFFU);
}
const uint32_t e2e_crc::lookup_table_profile_04_[256] = {
- 0x00000000U, 0x30850FF5U, 0x610A1FEAU, 0x518F101FU, 0xC2143FD4U, 0xF2913021U, 0xA31E203EU, 0x939B2FCBU, 0x159615F7U,
- 0x25131A02U, 0x749C0A1DU, 0x441905E8U, 0xD7822A23U, 0xE70725D6U, 0xB68835C9U, 0x860D3A3CU, 0x2B2C2BEEU, 0x1BA9241BU,
- 0x4A263404U, 0x7AA33BF1U, 0xE938143AU, 0xD9BD1BCFU, 0x88320BD0U, 0xB8B70425U, 0x3EBA3E19U, 0x0E3F31ECU, 0x5FB021F3U,
- 0x6F352E06U, 0xFCAE01CDU, 0xCC2B0E38U, 0x9DA41E27U, 0xAD2111D2U, 0x565857DCU, 0x66DD5829U, 0x37524836U, 0x07D747C3U,
- 0x944C6808U, 0xA4C967FDU, 0xF54677E2U, 0xC5C37817U, 0x43CE422BU, 0x734B4DDEU, 0x22C45DC1U, 0x12415234U, 0x81DA7DFFU,
- 0xB15F720AU, 0xE0D06215U, 0xD0556DE0U, 0x7D747C32U, 0x4DF173C7U, 0x1C7E63D8U, 0x2CFB6C2DU, 0xBF6043E6U, 0x8FE54C13U,
- 0xDE6A5C0CU, 0xEEEF53F9U, 0x68E269C5U, 0x58676630U, 0x09E8762FU, 0x396D79DAU, 0xAAF65611U, 0x9A7359E4U, 0xCBFC49FBU,
- 0xFB79460EU, 0xACB0AFB8U, 0x9C35A04DU, 0xCDBAB052U, 0xFD3FBFA7U, 0x6EA4906CU, 0x5E219F99U, 0x0FAE8F86U, 0x3F2B8073U,
- 0xB926BA4FU, 0x89A3B5BAU, 0xD82CA5A5U, 0xE8A9AA50U, 0x7B32859BU, 0x4BB78A6EU, 0x1A389A71U, 0x2ABD9584U, 0x879C8456U,
- 0xB7198BA3U, 0xE6969BBCU, 0xD6139449U, 0x4588BB82U, 0x750DB477U, 0x2482A468U, 0x1407AB9DU, 0x920A91A1U, 0xA28F9E54U,
- 0xF3008E4BU, 0xC38581BEU, 0x501EAE75U, 0x609BA180U, 0x3114B19FU, 0x0191BE6AU, 0xFAE8F864U, 0xCA6DF791U, 0x9BE2E78EU,
- 0xAB67E87BU, 0x38FCC7B0U, 0x0879C845U, 0x59F6D85AU, 0x6973D7AFU, 0xEF7EED93U, 0xDFFBE266U, 0x8E74F279U, 0xBEF1FD8CU,
- 0x2D6AD247U, 0x1DEFDDB2U, 0x4C60CDADU, 0x7CE5C258U, 0xD1C4D38AU, 0xE141DC7FU, 0xB0CECC60U, 0x804BC395U, 0x13D0EC5EU,
- 0x2355E3ABU, 0x72DAF3B4U, 0x425FFC41U, 0xC452C67DU, 0xF4D7C988U, 0xA558D997U, 0x95DDD662U, 0x0646F9A9U, 0x36C3F65CU,
- 0x674CE643U, 0x57C9E9B6U, 0xC8DF352FU, 0xF85A3ADAU, 0xA9D52AC5U, 0x99502530U, 0x0ACB0AFBU, 0x3A4E050EU, 0x6BC11511U,
- 0x5B441AE4U, 0xDD4920D8U, 0xEDCC2F2DU, 0xBC433F32U, 0x8CC630C7U, 0x1F5D1F0CU, 0x2FD810F9U, 0x7E5700E6U, 0x4ED20F13U,
- 0xE3F31EC1U, 0xD3761134U, 0x82F9012BU, 0xB27C0EDEU, 0x21E72115U, 0x11622EE0U, 0x40ED3EFFU, 0x7068310AU, 0xF6650B36U,
- 0xC6E004C3U, 0x976F14DCU, 0xA7EA1B29U, 0x347134E2U, 0x04F43B17U, 0x557B2B08U, 0x65FE24FDU, 0x9E8762F3U, 0xAE026D06U,
- 0xFF8D7D19U, 0xCF0872ECU, 0x5C935D27U, 0x6C1652D2U, 0x3D9942CDU, 0x0D1C4D38U, 0x8B117704U, 0xBB9478F1U, 0xEA1B68EEU,
- 0xDA9E671BU, 0x490548D0U, 0x79804725U, 0x280F573AU, 0x188A58CFU, 0xB5AB491DU, 0x852E46E8U, 0xD4A156F7U, 0xE4245902U,
- 0x77BF76C9U, 0x473A793CU, 0x16B56923U, 0x263066D6U, 0xA03D5CEAU, 0x90B8531FU, 0xC1374300U, 0xF1B24CF5U, 0x6229633EU,
- 0x52AC6CCBU, 0x03237CD4U, 0x33A67321U, 0x646F9A97U, 0x54EA9562U, 0x0565857DU, 0x35E08A88U, 0xA67BA543U, 0x96FEAAB6U,
- 0xC771BAA9U, 0xF7F4B55CU, 0x71F98F60U, 0x417C8095U, 0x10F3908AU, 0x20769F7FU, 0xB3EDB0B4U, 0x8368BF41U, 0xD2E7AF5EU,
- 0xE262A0ABU, 0x4F43B179U, 0x7FC6BE8CU, 0x2E49AE93U, 0x1ECCA166U, 0x8D578EADU, 0xBDD28158U, 0xEC5D9147U, 0xDCD89EB2U,
- 0x5AD5A48EU, 0x6A50AB7BU, 0x3BDFBB64U, 0x0B5AB491U, 0x98C19B5AU, 0xA84494AFU, 0xF9CB84B0U, 0xC94E8B45U, 0x3237CD4BU,
- 0x02B2C2BEU, 0x533DD2A1U, 0x63B8DD54U, 0xF023F29FU, 0xC0A6FD6AU, 0x9129ED75U, 0xA1ACE280U, 0x27A1D8BCU, 0x1724D749U,
- 0x46ABC756U, 0x762EC8A3U, 0xE5B5E768U, 0xD530E89DU, 0x84BFF882U, 0xB43AF777U, 0x191BE6A5U, 0x299EE950U, 0x7811F94FU,
- 0x4894F6BAU, 0xDB0FD971U, 0xEB8AD684U, 0xBA05C69BU, 0x8A80C96EU, 0x0C8DF352U, 0x3C08FCA7U, 0x6D87ECB8U, 0x5D02E34DU,
- 0xCE99CC86U, 0xFE1CC373U, 0xAF93D36CU, 0x9F16DC99U
+ 0x00000000U, 0x30850FF5U, 0x610A1FEAU, 0x518F101FU, 0xC2143FD4U, 0xF2913021U, 0xA31E203EU, 0x939B2FCBU,
+ 0x159615F7U, 0x25131A02U, 0x749C0A1DU, 0x441905E8U, 0xD7822A23U, 0xE70725D6U, 0xB68835C9U, 0x860D3A3CU,
+ 0x2B2C2BEEU, 0x1BA9241BU, 0x4A263404U, 0x7AA33BF1U, 0xE938143AU, 0xD9BD1BCFU, 0x88320BD0U, 0xB8B70425U,
+ 0x3EBA3E19U, 0x0E3F31ECU, 0x5FB021F3U, 0x6F352E06U, 0xFCAE01CDU, 0xCC2B0E38U, 0x9DA41E27U, 0xAD2111D2U,
+ 0x565857DCU, 0x66DD5829U, 0x37524836U, 0x07D747C3U, 0x944C6808U, 0xA4C967FDU, 0xF54677E2U, 0xC5C37817U,
+ 0x43CE422BU, 0x734B4DDEU, 0x22C45DC1U, 0x12415234U, 0x81DA7DFFU, 0xB15F720AU, 0xE0D06215U, 0xD0556DE0U,
+ 0x7D747C32U, 0x4DF173C7U, 0x1C7E63D8U, 0x2CFB6C2DU, 0xBF6043E6U, 0x8FE54C13U, 0xDE6A5C0CU, 0xEEEF53F9U,
+ 0x68E269C5U, 0x58676630U, 0x09E8762FU, 0x396D79DAU, 0xAAF65611U, 0x9A7359E4U, 0xCBFC49FBU, 0xFB79460EU,
+ 0xACB0AFB8U, 0x9C35A04DU, 0xCDBAB052U, 0xFD3FBFA7U, 0x6EA4906CU, 0x5E219F99U, 0x0FAE8F86U, 0x3F2B8073U,
+ 0xB926BA4FU, 0x89A3B5BAU, 0xD82CA5A5U, 0xE8A9AA50U, 0x7B32859BU, 0x4BB78A6EU, 0x1A389A71U, 0x2ABD9584U,
+ 0x879C8456U, 0xB7198BA3U, 0xE6969BBCU, 0xD6139449U, 0x4588BB82U, 0x750DB477U, 0x2482A468U, 0x1407AB9DU,
+ 0x920A91A1U, 0xA28F9E54U, 0xF3008E4BU, 0xC38581BEU, 0x501EAE75U, 0x609BA180U, 0x3114B19FU, 0x0191BE6AU,
+ 0xFAE8F864U, 0xCA6DF791U, 0x9BE2E78EU, 0xAB67E87BU, 0x38FCC7B0U, 0x0879C845U, 0x59F6D85AU, 0x6973D7AFU,
+ 0xEF7EED93U, 0xDFFBE266U, 0x8E74F279U, 0xBEF1FD8CU, 0x2D6AD247U, 0x1DEFDDB2U, 0x4C60CDADU, 0x7CE5C258U,
+ 0xD1C4D38AU, 0xE141DC7FU, 0xB0CECC60U, 0x804BC395U, 0x13D0EC5EU, 0x2355E3ABU, 0x72DAF3B4U, 0x425FFC41U,
+ 0xC452C67DU, 0xF4D7C988U, 0xA558D997U, 0x95DDD662U, 0x0646F9A9U, 0x36C3F65CU, 0x674CE643U, 0x57C9E9B6U,
+ 0xC8DF352FU, 0xF85A3ADAU, 0xA9D52AC5U, 0x99502530U, 0x0ACB0AFBU, 0x3A4E050EU, 0x6BC11511U, 0x5B441AE4U,
+ 0xDD4920D8U, 0xEDCC2F2DU, 0xBC433F32U, 0x8CC630C7U, 0x1F5D1F0CU, 0x2FD810F9U, 0x7E5700E6U, 0x4ED20F13U,
+ 0xE3F31EC1U, 0xD3761134U, 0x82F9012BU, 0xB27C0EDEU, 0x21E72115U, 0x11622EE0U, 0x40ED3EFFU, 0x7068310AU,
+ 0xF6650B36U, 0xC6E004C3U, 0x976F14DCU, 0xA7EA1B29U, 0x347134E2U, 0x04F43B17U, 0x557B2B08U, 0x65FE24FDU,
+ 0x9E8762F3U, 0xAE026D06U, 0xFF8D7D19U, 0xCF0872ECU, 0x5C935D27U, 0x6C1652D2U, 0x3D9942CDU, 0x0D1C4D38U,
+ 0x8B117704U, 0xBB9478F1U, 0xEA1B68EEU, 0xDA9E671BU, 0x490548D0U, 0x79804725U, 0x280F573AU, 0x188A58CFU,
+ 0xB5AB491DU, 0x852E46E8U, 0xD4A156F7U, 0xE4245902U, 0x77BF76C9U, 0x473A793CU, 0x16B56923U, 0x263066D6U,
+ 0xA03D5CEAU, 0x90B8531FU, 0xC1374300U, 0xF1B24CF5U, 0x6229633EU, 0x52AC6CCBU, 0x03237CD4U, 0x33A67321U,
+ 0x646F9A97U, 0x54EA9562U, 0x0565857DU, 0x35E08A88U, 0xA67BA543U, 0x96FEAAB6U, 0xC771BAA9U, 0xF7F4B55CU,
+ 0x71F98F60U, 0x417C8095U, 0x10F3908AU, 0x20769F7FU, 0xB3EDB0B4U, 0x8368BF41U, 0xD2E7AF5EU, 0xE262A0ABU,
+ 0x4F43B179U, 0x7FC6BE8CU, 0x2E49AE93U, 0x1ECCA166U, 0x8D578EADU, 0xBDD28158U, 0xEC5D9147U, 0xDCD89EB2U,
+ 0x5AD5A48EU, 0x6A50AB7BU, 0x3BDFBB64U, 0x0B5AB491U, 0x98C19B5AU, 0xA84494AFU, 0xF9CB84B0U, 0xC94E8B45U,
+ 0x3237CD4BU, 0x02B2C2BEU, 0x533DD2A1U, 0x63B8DD54U, 0xF023F29FU, 0xC0A6FD6AU, 0x9129ED75U, 0xA1ACE280U,
+ 0x27A1D8BCU, 0x1724D749U, 0x46ABC756U, 0x762EC8A3U, 0xE5B5E768U, 0xD530E89DU, 0x84BFF882U, 0xB43AF777U,
+ 0x191BE6A5U, 0x299EE950U, 0x7811F94FU, 0x4894F6BAU, 0xDB0FD971U, 0xEB8AD684U, 0xBA05C69BU, 0x8A80C96EU,
+ 0x0C8DF352U, 0x3C08FCA7U, 0x6D87ECB8U, 0x5D02E34DU, 0xCE99CC86U, 0xFE1CC373U, 0xAF93D36CU, 0x9F16DC99U
};
/**
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)) {