summaryrefslogtreecommitdiff
path: root/implementation/e2e_protection
diff options
context:
space:
mode:
Diffstat (limited to 'implementation/e2e_protection')
-rw-r--r--implementation/e2e_protection/include/buffer/buffer.hpp48
-rw-r--r--implementation/e2e_protection/include/crc/crc.hpp32
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp38
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp56
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp46
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile_custom/checker.hpp41
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp41
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp38
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp27
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile_interface/profile_interface.hpp27
-rw-r--r--implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp25
-rw-r--r--implementation/e2e_protection/include/e2exf/config.hpp28
-rw-r--r--implementation/e2e_protection/src/buffer/buffer.cpp22
-rw-r--r--implementation/e2e_protection/src/crc/crc.cpp182
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp42
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile01/profile_01.cpp110
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp79
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp49
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile_custom/profile_custom.cpp28
-rw-r--r--implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp40
-rw-r--r--implementation/e2e_protection/src/e2exf/config.cpp16
21 files changed, 1015 insertions, 0 deletions
diff --git a/implementation/e2e_protection/include/buffer/buffer.hpp b/implementation/e2e_protection/include/buffer/buffer.hpp
new file mode 100644
index 0000000..5ddcf2e
--- /dev/null
+++ b/implementation/e2e_protection/include/buffer/buffer.hpp
@@ -0,0 +1,48 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_BUFFER_HPP
+#define VSOMEIP_E2E_BUFFER_HPP
+
+#include <stdexcept>
+#include <cstdint>
+#include <ostream>
+#include <vector>
+
+namespace vsomeip {
+
+using e2e_buffer = std::vector<uint8_t>;
+
+class buffer_view {
+ public:
+ buffer_view(const uint8_t *_data_ptr, size_t _data_length)
+ : data_ptr_(_data_ptr), data_length_(_data_length) {
+ }
+
+ buffer_view(const e2e_buffer &_buffer)
+ : data_ptr_(_buffer.data()), data_length_(_buffer.size()) {}
+
+ buffer_view(const e2e_buffer &_buffer, size_t _length)
+ : data_ptr_(_buffer.data()), data_length_(_length) {
+ }
+
+ buffer_view(const e2e_buffer &_buffer, size_t _begin, size_t _end)
+ : data_ptr_(_buffer.data() + _begin), data_length_(_end - _begin) {
+ }
+
+ const uint8_t *begin(void) const { return data_ptr_; }
+
+ const uint8_t *end(void) const { return data_ptr_ + data_length_; }
+
+private:
+ const uint8_t *data_ptr_;
+ size_t data_length_;
+};
+
+std::ostream &operator<<(std::ostream &_os, const e2e_buffer &_buffer);
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_BUFFER_HPP
diff --git a/implementation/e2e_protection/include/crc/crc.hpp b/implementation/e2e_protection/include/crc/crc.hpp
new file mode 100644
index 0000000..1a54312
--- /dev/null
+++ b/implementation/e2e_protection/include/crc/crc.hpp
@@ -0,0 +1,32 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_CRC_HPP
+#define VSOMEIP_E2E_CRC_HPP
+
+#include <cstdint>
+#include "../buffer/buffer.hpp"
+
+namespace vsomeip {
+
+class e2e_crc {
+ public:
+ static uint8_t calculate_profile_01(buffer_view _buffer_view,
+ const uint8_t _start_value = 0x00U);
+ static uint32_t calculate_profile_04(buffer_view _buffer_view,
+ const uint32_t _start_value = 0x00000000U);
+
+ static uint32_t calculate_profile_custom(buffer_view _buffer_view);
+
+ private:
+ static const uint8_t lookup_table_profile_01_[256];
+ static const uint32_t lookup_table_profile_04_[256];
+ static const uint32_t lookup_table_profile_custom_[256];
+
+};
+
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_CRC_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp b/implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp
new file mode 100644
index 0000000..5fa243a
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp
@@ -0,0 +1,38 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE01_CHECKER_HPP
+#define VSOMEIP_E2E_PROFILE01_CHECKER_HPP
+
+#include "../profile01/profile_01.hpp"
+#include "../profile_interface/checker.hpp"
+
+namespace vsomeip {
+namespace e2e {
+namespace profile01 {
+
+class profile_01_checker final : public e2e::profile_interface::checker {
+
+ public:
+ profile_01_checker(void) = delete;
+
+ // [SWS_E2E_00389] initialize state
+ explicit profile_01_checker(const profile_config &_config) :
+ config_(_config) {}
+
+ virtual void check(const e2e_buffer &_buffer,
+ e2e::profile_interface::generic_check_status &_generic_check_status) override final;
+
+private:
+ profile_config config_;
+ std::mutex check_mutex_;
+
+};
+
+} // namespace profile01
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE01_CHECKER_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp b/implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp
new file mode 100644
index 0000000..810ec56
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp
@@ -0,0 +1,56 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE01_PROFILE01_HPP
+#define VSOMEIP_E2E_PROFILE01_PROFILE01_HPP
+
+#include <cstdint>
+#include "../../../buffer/buffer.hpp"
+
+namespace vsomeip {
+namespace e2e {
+namespace profile01 {
+
+struct profile_config;
+
+class profile_01 {
+ public:
+ static uint8_t compute_crc(const profile_config &_config, const e2e_buffer &_buffer);
+
+ static bool is_buffer_length_valid(const profile_config &_config, const e2e_buffer &_buffer);
+};
+
+// [SWS_E2E_00200]
+enum class p01_data_id_mode : uint8_t {E2E_P01_DATAID_BOTH, E2E_P01_DATAID_ALT, E2E_P01_DATAID_LOW, E2E_P01_DATAID_NIBBLE};
+
+struct profile_config {
+ // [SWS_E2E_00018]
+ uint16_t crc_offset_;
+ uint16_t data_id_;
+ p01_data_id_mode data_id_mode_;
+ uint16_t data_length_;
+ uint16_t counter_offset_;
+ uint16_t data_id_nibble_offset_;
+
+ profile_config() = delete;
+
+ profile_config(uint16_t _crc_offset, uint16_t _data_id,
+ p01_data_id_mode _data_id_mode, uint16_t _data_length,
+ uint16_t _counter_offset, uint16_t _data_id_nibble_offset)
+
+ : crc_offset_(_crc_offset), data_id_(_data_id),
+ data_id_mode_(_data_id_mode), data_length_(_data_length),
+ counter_offset_(_counter_offset),
+ data_id_nibble_offset_(_data_id_nibble_offset) {
+ }
+ profile_config(const profile_config &_config) = default;
+ profile_config &operator=(const profile_config &_config) = default;
+};
+
+} // namespace profile01
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE01_PROFILE01_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp b/implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp
new file mode 100644
index 0000000..204c7a1
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp
@@ -0,0 +1,46 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE01_PROTECTOR_HPP
+#define VSOMEIP_E2E_PROFILE01_PROTECTOR_HPP
+
+#include <mutex>
+#include "../profile01/profile_01.hpp"
+#include "../profile_interface/protector.hpp"
+
+namespace vsomeip {
+namespace e2e {
+namespace profile01 {
+
+class protector final : public e2e::profile_interface::protector {
+ public:
+ protector(void) = delete;
+
+ explicit protector(const profile_config &_config) : config_(_config), counter_(0){};
+
+ void protect(e2e_buffer &_buffer) override final;
+
+ private:
+
+ void write_counter(e2e_buffer &_buffer);
+
+ void write_data_id(e2e_buffer &_buffer);
+
+ void write_crc(e2e_buffer &_buffer, uint8_t _computed_crc);
+
+ void increment_counter(void);
+
+
+ private:
+ profile_config config_;
+ uint8_t counter_;
+ std::mutex protect_mutex_;
+};
+
+} // namespace profile01
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE01_PROTECTOR_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile_custom/checker.hpp b/implementation/e2e_protection/include/e2e/profile/profile_custom/checker.hpp
new file mode 100644
index 0000000..7080329
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile_custom/checker.hpp
@@ -0,0 +1,41 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE_CUSTOM_CHECKER_HPP
+#define VSOMEIP_E2E_PROFILE_CUSTOM_CHECKER_HPP
+
+#include "../profile_custom/profile_custom.hpp"
+#include "../profile_interface/checker.hpp"
+#include <mutex>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_custom {
+
+class profile_custom_checker final : public vsomeip::e2e::profile_interface::checker {
+
+ public:
+ profile_custom_checker(void) = delete;
+
+ explicit profile_custom_checker(const vsomeip::e2e::profile_custom::profile_config &_config) :
+ config_(_config) {}
+
+ virtual void check(const e2e_buffer &_buffer,
+ vsomeip::e2e::profile_interface::generic_check_status &_generic_check_status);
+
+ private:
+ uint32_t read_crc(const e2e_buffer &_buffer) const;
+
+private:
+ profile_config config_;
+ std::mutex check_mutex_;
+
+};
+
+} // namespace profile_custom
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE_CUSTOM_CHECKER_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp b/implementation/e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp
new file mode 100644
index 0000000..f41942c
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp
@@ -0,0 +1,41 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE_CUSTOM_PROFILE_CUSTOM_HPP
+#define VSOMEIP_E2E_PROFILE_CUSTOM_PROFILE_CUSTOM_HPP
+
+#include <cstdint>
+#include "../../../buffer/buffer.hpp"
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_custom {
+
+struct profile_config;
+
+class profile_custom {
+ public:
+ static uint32_t compute_crc(const profile_config &_config, const e2e_buffer &_buffer);
+
+ static bool is_buffer_length_valid(const profile_config &_config, const e2e_buffer &_buffer);
+};
+
+struct profile_config {
+ uint16_t crc_offset_;
+
+ profile_config() = delete;
+
+ profile_config(uint16_t _crc_offset)
+ : crc_offset_(_crc_offset) {
+ }
+ profile_config(const profile_config &_config) = default;
+ profile_config &operator=(const profile_config &_config) = default;
+};
+
+} // namespace profile_custom
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE_CUSTOM_PROFILE_CUSTOM_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp b/implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp
new file mode 100644
index 0000000..4b6c3b4
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp
@@ -0,0 +1,38 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE_CUSTOM_PROTECTOR_HPP
+#define VSOMEIP_E2E_PROFILE_CUSTOM_PROTECTOR_HPP
+
+#include <mutex>
+#include "../profile_custom/profile_custom.hpp"
+#include "../profile_interface/protector.hpp"
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_custom {
+
+class protector final : public vsomeip::e2e::profile_interface::protector {
+ public:
+ protector(void) = delete;
+
+ explicit protector(const profile_config &_config) : config_(_config){};
+
+ void protect(e2e_buffer &_buffer) override final;
+
+ private:
+
+ void write_crc(e2e_buffer &_buffer, uint32_t _computed_crc);
+
+ private:
+ profile_config config_;
+ std::mutex protect_mutex_;
+};
+
+} // namespace profile_custom
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE_CUSTOM_PROTECTOR_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp b/implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp
new file mode 100644
index 0000000..c66d1b0
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp
@@ -0,0 +1,27 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE_INTERFACE_CHECKER_HPP
+#define VSOMEIP_E2E_PROFILE_INTERFACE_CHECKER_HPP
+
+#include "../profile_interface/profile_interface.hpp"
+#include "../../../buffer/buffer.hpp"
+#include <mutex>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_interface {
+
+class checker : public profile_interface {
+ public:
+ virtual void check(const e2e_buffer &_buffer,
+ vsomeip::e2e::profile_interface::generic_check_status &_generic_check_status) = 0;
+};
+
+} // namespace profile_interface
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE_INTERFACE_CHECKER_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile_interface/profile_interface.hpp b/implementation/e2e_protection/include/e2e/profile/profile_interface/profile_interface.hpp
new file mode 100644
index 0000000..377bbee
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile_interface/profile_interface.hpp
@@ -0,0 +1,27 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE_INTERFACE_PROFILE_INTERFACE_HPP
+#define VSOMEIP_E2E_PROFILE_INTERFACE_PROFILE_INTERFACE_HPP
+
+#include <cstdint>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_interface {
+
+enum class generic_check_status : uint8_t { E2E_OK, E2E_WRONG_CRC, E2E_ERROR};
+
+class profile_interface {
+public:
+ virtual ~profile_interface() {
+ }
+};
+
+} // namespace profile_interface
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE_INTERFACE_PROFILE_INTERFACE_HPP
diff --git a/implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp b/implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp
new file mode 100644
index 0000000..a031a9e
--- /dev/null
+++ b/implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp
@@ -0,0 +1,25 @@
+// 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/.
+
+#ifndef VSOMEIP_E2E_PROFILE_INTERFACE_PROTECTOR_HPP
+#define VSOMEIP_E2E_PROFILE_INTERFACE_PROTECTOR_HPP
+
+#include "../../../buffer/buffer.hpp"
+#include "../profile_interface/profile_interface.hpp"
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_interface {
+
+class protector : public profile_interface {
+ public:
+ virtual void protect(e2e_buffer &_buffer) = 0;
+};
+
+} // namespace profile_interface
+} // namespace e2e
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2E_PROFILE_INTERFACE_PROTECTOR_HPP
diff --git a/implementation/e2e_protection/include/e2exf/config.hpp b/implementation/e2e_protection/include/e2exf/config.hpp
new file mode 100644
index 0000000..3667211
--- /dev/null
+++ b/implementation/e2e_protection/include/e2exf/config.hpp
@@ -0,0 +1,28 @@
+// 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/.
+
+#ifndef VSOMEIP_E2EXF_CONFIG_HPP
+#define VSOMEIP_E2EXF_CONFIG_HPP
+
+#include "../e2e/profile/profile_interface/checker.hpp"
+#include "../e2e/profile/profile_interface/protector.hpp"
+
+#include <memory>
+#include <map>
+
+namespace vsomeip {
+namespace e2exf {
+
+using session_id = uint16_t;
+using instance_id = uint16_t;
+
+using data_identifier = std::pair<session_id, instance_id>;
+
+std::ostream &operator<<(std::ostream &_os, const e2exf::data_identifier &_data_identifier);
+
+} // namespace e2exf
+} // namespace vsomeip
+
+#endif // VSOMEIP_E2EXF_CONFIG_HPP
diff --git a/implementation/e2e_protection/src/buffer/buffer.cpp b/implementation/e2e_protection/src/buffer/buffer.cpp
new file mode 100644
index 0000000..e133d42
--- /dev/null
+++ b/implementation/e2e_protection/src/buffer/buffer.cpp
@@ -0,0 +1,22 @@
+// 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 "../../../e2e_protection/include/buffer/buffer.hpp"
+#include <iomanip>
+
+namespace vsomeip {
+
+std::ostream &operator<<(std::ostream &_os, const e2e_buffer &_buffer) {
+ for (auto b : _buffer) {
+ if (isupper(b)) {
+ _os << b;
+ } else {
+ _os << "[" << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)b << std::dec << "]";
+ }
+ }
+ return _os;
+}
+
+} // namespace vsomeip
diff --git a/implementation/e2e_protection/src/crc/crc.cpp b/implementation/e2e_protection/src/crc/crc.cpp
new file mode 100644
index 0000000..d9f1f99
--- /dev/null
+++ b/implementation/e2e_protection/src/crc/crc.cpp
@@ -0,0 +1,182 @@
+// 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 "../../include/crc/crc.hpp"
+#include <iostream>
+#include <string>
+#include <iomanip>
+
+namespace vsomeip {
+
+/**
+ * Calculates the crc over the provided range.
+ *
+ * @param begin Constant iterator pointing to begin of the range.
+ * @param end Constant iterator pointing to end of the range.
+ * @param startValue The crc value from previous call.
+ * @return The calculated crc value.
+ *
+ * Parameters of the CRC:
+ * - Width = 8
+ * - Poly = 0x1D
+ * - XorIn = 0xFF
+ * - ReflectIn = false
+ * - XorOut = 0xFF
+ * - ReflectOut = false
+ * - Algorithm = table-driven
+ */
+uint8_t e2e_crc::calculate_profile_01(buffer_view _buffer_view, const uint8_t _start_value) {
+ uint8_t crc = _start_value ^ 0xFFU;
+ for (uint8_t byte : _buffer_view) {
+ crc = static_cast<uint8_t>(lookup_table_profile_01_[static_cast<uint8_t>((byte) ^ crc)] ^ (crc >> 8U));
+ }
+ crc = crc ^ 0xFFU;
+ return crc;
+}
+
+const uint8_t e2e_crc::lookup_table_profile_01_[256] = {
+ 0x00U, 0x1DU, 0x3AU, 0x27U, 0x74U, 0x69U, 0x4EU, 0x53U, 0xE8U, 0xF5U, 0xD2U, 0xCFU, 0x9CU, 0x81U, 0xA6U, 0xBBU,
+ 0xCDU, 0xD0U, 0xF7U, 0xEAU, 0xB9U, 0xA4U, 0x83U, 0x9EU, 0x25U, 0x38U, 0x1FU, 0x02U, 0x51U, 0x4CU, 0x6BU, 0x76U,
+ 0x87U, 0x9AU, 0xBDU, 0xA0U, 0xF3U, 0xEEU, 0xC9U, 0xD4U, 0x6FU, 0x72U, 0x55U, 0x48U, 0x1BU, 0x06U, 0x21U, 0x3CU,
+ 0x4AU, 0x57U, 0x70U, 0x6DU, 0x3EU, 0x23U, 0x04U, 0x19U, 0xA2U, 0xBFU, 0x98U, 0x85U, 0xD6U, 0xCBU, 0xECU, 0xF1U,
+ 0x13U, 0x0EU, 0x29U, 0x34U, 0x67U, 0x7AU, 0x5DU, 0x40U, 0xFBU, 0xE6U, 0xC1U, 0xDCU, 0x8FU, 0x92U, 0xB5U, 0xA8U,
+ 0xDEU, 0xC3U, 0xE4U, 0xF9U, 0xAAU, 0xB7U, 0x90U, 0x8DU, 0x36U, 0x2BU, 0x0CU, 0x11U, 0x42U, 0x5FU, 0x78U, 0x65U,
+ 0x94U, 0x89U, 0xAEU, 0xB3U, 0xE0U, 0xFDU, 0xDAU, 0xC7U, 0x7CU, 0x61U, 0x46U, 0x5BU, 0x08U, 0x15U, 0x32U, 0x2FU,
+ 0x59U, 0x44U, 0x63U, 0x7EU, 0x2DU, 0x30U, 0x17U, 0x0AU, 0xB1U, 0xACU, 0x8BU, 0x96U, 0xC5U, 0xD8U, 0xFFU, 0xE2U,
+ 0x26U, 0x3BU, 0x1CU, 0x01U, 0x52U, 0x4FU, 0x68U, 0x75U, 0xCEU, 0xD3U, 0xF4U, 0xE9U, 0xBAU, 0xA7U, 0x80U, 0x9DU,
+ 0xEBU, 0xF6U, 0xD1U, 0xCCU, 0x9FU, 0x82U, 0xA5U, 0xB8U, 0x03U, 0x1EU, 0x39U, 0x24U, 0x77U, 0x6AU, 0x4DU, 0x50U,
+ 0xA1U, 0xBCU, 0x9BU, 0x86U, 0xD5U, 0xC8U, 0xEFU, 0xF2U, 0x49U, 0x54U, 0x73U, 0x6EU, 0x3DU, 0x20U, 0x07U, 0x1AU,
+ 0x6CU, 0x71U, 0x56U, 0x4BU, 0x18U, 0x05U, 0x22U, 0x3FU, 0x84U, 0x99U, 0xBEU, 0xA3U, 0xF0U, 0xEDU, 0xCAU, 0xD7U,
+ 0x35U, 0x28U, 0x0FU, 0x12U, 0x41U, 0x5CU, 0x7BU, 0x66U, 0xDDU, 0xC0U, 0xE7U, 0xFAU, 0xA9U, 0xB4U, 0x93U, 0x8EU,
+ 0xF8U, 0xE5U, 0xC2U, 0xDFU, 0x8CU, 0x91U, 0xB6U, 0xABU, 0x10U, 0x0DU, 0x2AU, 0x37U, 0x64U, 0x79U, 0x5EU, 0x43U,
+ 0xB2U, 0xAFU, 0x88U, 0x95U, 0xC6U, 0xDBU, 0xFCU, 0xE1U, 0x5AU, 0x47U, 0x60U, 0x7DU, 0x2EU, 0x33U, 0x14U, 0x09U,
+ 0x7FU, 0x62U, 0x45U, 0x58U, 0x0BU, 0x16U, 0x31U, 0x2CU, 0x97U, 0x8AU, 0xADU, 0xB0U, 0xE3U, 0xFEU, 0xD9U, 0xC4U
+};
+
+/**
+* Calculates the CRC over the provided range.
+*
+* @param begin Constant iterator pointing to begin of the range.
+* @param end Constant iterator pointing to end of the range.
+* @param startValue The CRC value from previous call.
+* @return The calculated CRC value.
+*
+* Parameters of the CRC:
+* - Width = 32
+* - Poly = 0xF4ACFB13
+* - XorIn = 0xFFFFFFFF
+* - ReflectIn = true
+* - XorOut = 0xFFFFFFFF
+* - 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;
+
+ return crc;
+}
+
+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
+};
+
+/**
+* Calculates the CRC over the provided range.
+*
+* @param begin Constant iterator pointing to begin of the range.
+* @param end Constant iterator pointing to end of the range.
+* @param startValue The CRC value from previous call.
+* @return The calculated CRC value.
+*
+* Parameters of the CRC:
+* - Width = 32
+* - Poly = 0x4C11DB7
+* - InitValue = 0xFFFFFFFF
+* - ReflectIn = true
+* - XorOut = 0xFFFFFFFF
+* - ReflectOut = true
+*/
+uint32_t e2e_crc::calculate_profile_custom(buffer_view _buffer_view) {
+ // InitValue
+ uint32_t crc = 0xFFFFFFFFU;
+
+ for (uint8_t byte : _buffer_view) {
+ crc = lookup_table_profile_custom_[static_cast<uint8_t>(byte ^ crc)] ^ (crc >> 8U);
+ }
+
+ // XorOut
+ crc = crc ^ 0xFFFFFFFFU;
+ return crc;
+}
+
+const uint32_t e2e_crc::lookup_table_profile_custom_[256] = {
+ 0x00000000U, 0x77073096U, 0xEE0E612CU, 0x990951BAU, 0x076DC419U, 0x706AF48FU, 0xE963A535U, 0x9E6495A3U,
+ 0x0EDB8832U, 0x79DCB8A4U, 0xE0D5E91EU, 0x97D2D988U, 0x09B64C2BU, 0x7EB17CBDU, 0xE7B82D07U, 0x90BF1D91U,
+ 0x1DB71064U, 0x6AB020F2U, 0xF3B97148U, 0x84BE41DEU, 0x1ADAD47DU, 0x6DDDE4EBU, 0xF4D4B551U, 0x83D385C7U,
+ 0x136C9856U, 0x646BA8C0U, 0xFD62F97AU, 0x8A65C9ECU, 0x14015C4FU, 0x63066CD9U, 0xFA0F3D63U, 0x8D080DF5U,
+ 0x3B6E20C8U, 0x4C69105EU, 0xD56041E4U, 0xA2677172U, 0x3C03E4D1U, 0x4B04D447U, 0xD20D85FDU, 0xA50AB56BU,
+ 0x35B5A8FAU, 0x42B2986CU, 0xDBBBC9D6U, 0xACBCF940U, 0x32D86CE3U, 0x45DF5C75U, 0xDCD60DCFU, 0xABD13D59U,
+ 0x26D930ACU, 0x51DE003AU, 0xC8D75180U, 0xBFD06116U, 0x21B4F4B5U, 0x56B3C423U, 0xCFBA9599U, 0xB8BDA50FU,
+ 0x2802B89EU, 0x5F058808U, 0xC60CD9B2U, 0xB10BE924U, 0x2F6F7C87U, 0x58684C11U, 0xC1611DABU, 0xB6662D3DU,
+ 0x76DC4190U, 0x01DB7106U, 0x98D220BCU, 0xEFD5102AU, 0x71B18589U, 0x06B6B51FU, 0x9FBFE4A5U, 0xE8B8D433U,
+ 0x7807C9A2U, 0x0F00F934U, 0x9609A88EU, 0xE10E9818U, 0x7F6A0DBBU, 0x086D3D2DU, 0x91646C97U, 0xE6635C01U,
+ 0x6B6B51F4U, 0x1C6C6162U, 0x856530D8U, 0xF262004EU, 0x6C0695EDU, 0x1B01A57BU, 0x8208F4C1U, 0xF50FC457U,
+ 0x65B0D9C6U, 0x12B7E950U, 0x8BBEB8EAU, 0xFCB9887CU, 0x62DD1DDFU, 0x15DA2D49U, 0x8CD37CF3U, 0xFBD44C65U,
+ 0x4DB26158U, 0x3AB551CEU, 0xA3BC0074U, 0xD4BB30E2U, 0x4ADFA541U, 0x3DD895D7U, 0xA4D1C46DU, 0xD3D6F4FBU,
+ 0x4369E96AU, 0x346ED9FCU, 0xAD678846U, 0xDA60B8D0U, 0x44042D73U, 0x33031DE5U, 0xAA0A4C5FU, 0xDD0D7CC9U,
+ 0x5005713CU, 0x270241AAU, 0xBE0B1010U, 0xC90C2086U, 0x5768B525U, 0x206F85B3U, 0xB966D409U, 0xCE61E49FU,
+ 0x5EDEF90EU, 0x29D9C998U, 0xB0D09822U, 0xC7D7A8B4U, 0x59B33D17U, 0x2EB40D81U, 0xB7BD5C3BU, 0xC0BA6CADU,
+ 0xEDB88320U, 0x9ABFB3B6U, 0x03B6E20CU, 0x74B1D29AU, 0xEAD54739U, 0x9DD277AFU, 0x04DB2615U, 0x73DC1683U,
+ 0xE3630B12U, 0x94643B84U, 0x0D6D6A3EU, 0x7A6A5AA8U, 0xE40ECF0BU, 0x9309FF9DU, 0x0A00AE27U, 0x7D079EB1U,
+ 0xF00F9344U, 0x8708A3D2U, 0x1E01F268U, 0x6906C2FEU, 0xF762575DU, 0x806567CBU, 0x196C3671U, 0x6E6B06E7U,
+ 0xFED41B76U, 0x89D32BE0U, 0x10DA7A5AU, 0x67DD4ACCU, 0xF9B9DF6FU, 0x8EBEEFF9U, 0x17B7BE43U, 0x60B08ED5U,
+ 0xD6D6A3E8U, 0xA1D1937EU, 0x38D8C2C4U, 0x4FDFF252U, 0xD1BB67F1U, 0xA6BC5767U, 0x3FB506DDU, 0x48B2364BU,
+ 0xD80D2BDAU, 0xAF0A1B4CU, 0x36034AF6U, 0x41047A60U, 0xDF60EFC3U, 0xA867DF55U, 0x316E8EEFU, 0x4669BE79U,
+ 0xCB61B38CU, 0xBC66831AU, 0x256FD2A0U, 0x5268E236U, 0xCC0C7795U, 0xBB0B4703U, 0x220216B9U, 0x5505262FU,
+ 0xC5BA3BBEU, 0xB2BD0B28U, 0x2BB45A92U, 0x5CB36A04U, 0xC2D7FFA7U, 0xB5D0CF31U, 0x2CD99E8BU, 0x5BDEAE1DU,
+ 0x9B64C2B0U, 0xEC63F226U, 0x756AA39CU, 0x026D930AU, 0x9C0906A9U, 0xEB0E363FU, 0x72076785U, 0x05005713U,
+ 0x95BF4A82U, 0xE2B87A14U, 0x7BB12BAEU, 0x0CB61B38U, 0x92D28E9BU, 0xE5D5BE0DU, 0x7CDCEFB7U, 0x0BDBDF21U,
+ 0x86D3D2D4U, 0xF1D4E242U, 0x68DDB3F8U, 0x1FDA836EU, 0x81BE16CDU, 0xF6B9265BU, 0x6FB077E1U, 0x18B74777U,
+ 0x88085AE6U, 0xFF0F6A70U, 0x66063BCAU, 0x11010B5CU, 0x8F659EFFU, 0xF862AE69U, 0x616BFFD3U, 0x166CCF45U,
+ 0xA00AE278U, 0xD70DD2EEU, 0x4E048354U, 0x3903B3C2U, 0xA7672661U, 0xD06016F7U, 0x4969474DU, 0x3E6E77DBU,
+ 0xAED16A4AU, 0xD9D65ADCU, 0x40DF0B66U, 0x37D83BF0U, 0xA9BCAE53U, 0xDEBB9EC5U, 0x47B2CF7FU, 0x30B5FFE9U,
+ 0xBDBDF21CU, 0xCABAC28AU, 0x53B39330U, 0x24B4A3A6U, 0xBAD03605U, 0xCDD70693U, 0x54DE5729U, 0x23D967BFU,
+ 0xB3667A2EU, 0xC4614AB8U, 0x5D681B02U, 0x2A6F2B94U, 0xB40BBE37U, 0xC30C8EA1U, 0x5A05DF1BU, 0x2D02EF8DU
+};
+
+} // namespace vsomeip
+
diff --git a/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp b/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp
new file mode 100644
index 0000000..e4c0504
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile01/checker.cpp
@@ -0,0 +1,42 @@
+// 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 "../../../../../e2e_protection/include/e2e/profile/profile01/checker.hpp"
+#include "../../../../../logging/include/logger.hpp"
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <iomanip>
+#include <algorithm>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile01 {
+
+// [SWS_E2E_00196]
+void profile_01_checker::check(const e2e_buffer &_buffer,
+ e2e::profile_interface::generic_check_status &_generic_check_status) {
+ std::lock_guard<std::mutex> lock(check_mutex_);
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_ERROR;
+
+ if (profile_01::is_buffer_length_valid(config_, _buffer)) {
+ uint8_t received_crc(0);
+ uint8_t calculated_crc(0);
+ received_crc = _buffer[config_.crc_offset_];
+ calculated_crc = profile_01::compute_crc(config_, _buffer);
+ if (received_crc == calculated_crc) {
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_OK;
+ } else {
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_WRONG_CRC;
+ VSOMEIP_INFO << std::hex << "E2E protection: CRC8 does not match: calculated CRC: "
+ << (uint32_t) calculated_crc << " received CRC: " << (uint32_t) received_crc;
+ }
+ }
+ return;
+}
+
+} // namespace profile01
+} // namespace e2e
+} // namespace vsomeip
diff --git a/implementation/e2e_protection/src/e2e/profile/profile01/profile_01.cpp b/implementation/e2e_protection/src/e2e/profile/profile01/profile_01.cpp
new file mode 100644
index 0000000..72bd14c
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile01/profile_01.cpp
@@ -0,0 +1,110 @@
+// 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 "../../../../../e2e_protection/include/e2e/profile/profile01/profile_01.hpp"
+#include "../../../../../e2e_protection/include/crc/crc.hpp"
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <iomanip>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile01 {
+
+uint8_t profile_01::compute_crc(const profile_config &_config, const e2e_buffer &_buffer) {
+ uint8_t computed_crc = 0xFF;
+ e2e_buffer data_id_buffer; //(_data, _data+_size);
+ data_id_buffer.push_back((uint8_t) (_config.data_id_ >> 8)); // insert MSB
+ data_id_buffer.push_back((uint8_t) _config.data_id_); // insert LSB
+
+ switch (_config.data_id_mode_) {
+ case p01_data_id_mode::E2E_P01_DATAID_BOTH: // CRC over 2 bytes
+ /*
+ * Two bytes are included in the CRC (double ID configuration) This is used in E2E variant 1A.
+ */
+ // CRC = Crc_CalculateCRC8(Config->DataID, 1, 0xFF, FALSE)
+ computed_crc = e2e_crc::calculate_profile_01(buffer_view(data_id_buffer, 1, 2), 0xFF); //CRC over low byte of Data ID (LSB)
+
+ // CRC = Crc_CalculateCRC8(Config->DataID >> 8, 1, CRC, FALSE)
+ computed_crc = e2e_crc::calculate_profile_01(buffer_view(data_id_buffer, 0, 1), computed_crc); //CRC over high byte of Data ID (MSB)
+
+ break;
+ case p01_data_id_mode::E2E_P01_DATAID_LOW: // CRC over low byte only
+ /*
+ * Only the low byte is included, the high byte is never used.
+ * This is applicable if the IDs in a particular system are 8 bits
+ */
+ // CRC = Crc_CalculateCRC8(Config->DataID, 1, 0xFF, FALSE)
+ computed_crc = e2e_crc::calculate_profile_01(buffer_view(data_id_buffer, 1, 2), 0xFF); //CRC over low byte of Data ID (LSB)
+ break;
+
+ case p01_data_id_mode::E2E_P01_DATAID_ALT:
+ /* One of the two bytes byte is included, alternating high and low byte,
+ * depending on parity of the counter (alternating ID configuration).
+ * For an even counter, the low byte is included.
+ * For an odd counter, the high byte is included.
+ * This is used in E2E variant 1B.
+ *
+ if( counter % 2 == 0) {
+ // CRC = Crc_CalculateCRC8(Config->DataID, 1, 0xFF, FALSE)
+ computed_crc = crc::e2e_crc::calculate_profile_01(buffer::buffer_view(data_id_buffer, 1, 2), 0xFF); //CRC over low byte of Data ID (LSB)
+ } else {
+ // CRC = Crc_CalculateCRC8(Config->DataID >> 8, 1, 0xFF, FALSE)
+ computed_crc = crc::e2e_crc::calculate_profile_01(buffer::buffer_view(data_id_buffer, 0, 1), 0xFF); //CRC over high byte of Data ID (MSB)
+ }
+ */
+ break;
+
+ case p01_data_id_mode::E2E_P01_DATAID_NIBBLE:
+ /*
+ * The low byte is included in the implicit CRC calculation,
+ * the low nibble of the high byte is transmitted along with
+ * the data (i.e. it is explicitly included), the high nibble of
+ * the high byte is not used. This is applicable for the IDs
+ * up to 12 bits. This is used in E2E variant 1C.
+ */
+ // CRC = Crc_CalculateCRC8(Config->DataID, 1, 0xFF, FALSE)
+ computed_crc = e2e_crc::calculate_profile_01(buffer_view(data_id_buffer, 1, 2), 0xFF); //CRC over low byte of Data ID (LSB)
+
+ // CRC = Crc_CalculateCRC8 (0, 1, CRC, FALSE)
+ data_id_buffer.clear();
+ data_id_buffer.push_back(0x00);
+ computed_crc = e2e_crc::calculate_profile_01(buffer_view(data_id_buffer, 0, 1), computed_crc); // CRC with 0x00
+ break;
+
+ default:
+ break;
+ }
+
+ // Compute CRC over the area before the CRC (if CRC is not the first byte)
+ if (_config.crc_offset_ >= 1) {
+ // CRC = Crc_CalculateCRC8 (Data, (Config->CRCOffset / 8), CRC, FALSE)
+ computed_crc = e2e_crc::calculate_profile_01(buffer_view(_buffer, 0, _config.crc_offset_), computed_crc);
+ }
+
+ // Compute the area after CRC, if CRC is not the last byte. Start with the byte after CRC, finish with the last byte of Data.
+ if ((_config.crc_offset_) < (_config.data_length_ / 8) - 1) {
+ // CRC = Crc_CalculateCRC8 (& Data[Config->CRCOffset/8 + 1], (Config->DataLength / 8 - Config->CRCOffset / 8 - 1), CRC, FALSE)
+ computed_crc = e2e_crc::calculate_profile_01(buffer_view(_buffer, _config.crc_offset_ + 1, _buffer.size()), computed_crc);
+ }
+
+ // CRC = CRC ^ 0xFF
+ // To negate the last XOR 0xFF operation done on computed CRC by the last CalculateCRC8(), there is a XORing doneexternally by E2E Library
+ computed_crc = computed_crc ^ 0xFFU;
+ return computed_crc;
+}
+
+/** @req [SWS_E2E_00356] */
+bool profile_01::is_buffer_length_valid(const profile_config &_config, const e2e_buffer &_buffer) {
+ return (((_config.data_length_ / 8) + 1U <= _buffer.size())
+ && _config.crc_offset_ <= _buffer.size()
+ && _config.counter_offset_ / 8 <= _buffer.size()
+ && _config.data_id_nibble_offset_ / 8 <= _buffer.size());
+}
+
+} // namespace profile01
+} // namespace e2e
+} // namespace vsomeip
diff --git a/implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp b/implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp
new file mode 100644
index 0000000..0bf0199
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile01/protector.cpp
@@ -0,0 +1,79 @@
+// 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 "../../../../../e2e_protection/include/e2e/profile/profile01/protector.hpp"
+#include "../../../../../logging/include/logger.hpp"
+
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <iomanip>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile01 {
+
+/** @req [SWS_E2E_00195] */
+void protector::protect(e2e_buffer &_buffer) {
+ std::lock_guard<std::mutex> lock(protect_mutex_);
+
+ if (profile_01::is_buffer_length_valid(config_, _buffer)) {
+ // write the current Counter value in Data
+ write_counter(_buffer);
+
+ // write DataID nibble in Data (E2E_P01_DATAID_NIBBLE) in Data
+ write_data_id(_buffer);
+
+ // compute the CRC over DataID and Data
+ uint8_t computed_crc = profile_01::compute_crc(config_, _buffer);
+ // write CRC in Data
+ write_crc(_buffer, computed_crc);
+
+ // increment the Counter (new value will be used in the next invocation of E2E_P01Protect()),
+ increment_counter();
+ }
+}
+
+/** @req [SRS_E2E_08528] */
+void protector::write_counter(e2e_buffer &_buffer) {
+ if (config_.counter_offset_ % 8 == 0) {
+ // write write counter value into low nibble
+ _buffer[config_.counter_offset_ / 8] =
+ static_cast<uint8_t>((_buffer[config_.counter_offset_ / 8] & 0xF0) | (counter_ & 0x0F));
+ } else {
+ // write counter into high nibble
+ _buffer[config_.counter_offset_ / 8] =
+ static_cast<uint8_t>((_buffer[config_.counter_offset_ / 8] & 0x0F) | ((counter_ << 4) & 0xF0));
+ }
+}
+
+/** @req [SRS_E2E_08528] */
+void protector::write_data_id(e2e_buffer &_buffer) {
+ if (config_.data_id_mode_ == p01_data_id_mode::E2E_P01_DATAID_NIBBLE) {
+ if (config_.data_id_nibble_offset_ % 8 == 0) {
+ // write low nibble of high byte of Data ID
+ _buffer[config_.data_id_nibble_offset_ / 8] =
+ static_cast<uint8_t>((_buffer[config_.data_id_nibble_offset_ / 8] & 0xF0) | ((config_.data_id_ >> 8) & 0x0F));
+ } else {
+ // write low nibble of high byte of Data ID
+ _buffer[config_.data_id_nibble_offset_ / 8] =
+ static_cast<uint8_t>((_buffer[config_.data_id_nibble_offset_ / 8] & 0x0F) | ((config_.data_id_ >> 4) & 0xF0));
+ }
+ }
+}
+
+/** @req [SRS_E2E_08528] */
+void protector::write_crc(e2e_buffer &_buffer, uint8_t _computed_crc) {
+ _buffer[config_.crc_offset_] = _computed_crc;
+}
+
+/** @req [SWS_E2E_00075] */
+void protector::increment_counter(void) {
+ counter_ = static_cast<uint8_t>((counter_ + 1U) % 15);
+}
+
+} // namespace profile01
+} // namespace e2e
+} // namespace vsomeip
diff --git a/implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp b/implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp
new file mode 100644
index 0000000..eb6f557
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile_custom/checker.cpp
@@ -0,0 +1,49 @@
+// 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 "../../../../../e2e_protection/include/e2e/profile/profile_custom/checker.hpp"
+#include "../../../../../logging/include/logger.hpp"
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <iomanip>
+#include <algorithm>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_custom {
+
+void profile_custom_checker::check(const e2e_buffer &_buffer,
+ e2e::profile_interface::generic_check_status &_generic_check_status) {
+ 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)) {
+ uint32_t received_crc(0);
+ uint32_t calculated_crc(0);
+
+ received_crc = read_crc(_buffer);
+ calculated_crc = profile_custom::compute_crc(config_, _buffer);
+ if (received_crc == calculated_crc) {
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_OK;
+ } else {
+ _generic_check_status = e2e::profile_interface::generic_check_status::E2E_WRONG_CRC;
+ VSOMEIP_INFO << std::hex << "E2E protection: CRC32 does not match: calculated CRC: "
+ << (uint32_t) calculated_crc << " received CRC: " << (uint32_t) received_crc;
+ }
+ }
+ return;
+}
+
+uint32_t profile_custom_checker::read_crc(const e2e_buffer &_buffer) const {
+ return (static_cast<uint32_t>(_buffer[config_.crc_offset_ ]) << 24U) |
+ (static_cast<uint32_t>(_buffer[config_.crc_offset_ + 1U]) << 16U) |
+ (static_cast<uint32_t>(_buffer[config_.crc_offset_ + 2U]) << 8U) |
+ static_cast<uint32_t>(_buffer[config_.crc_offset_ + 3U]);
+}
+
+} // namespace profile_custom
+} // namespace e2e
+} // namespace vsomeip
diff --git a/implementation/e2e_protection/src/e2e/profile/profile_custom/profile_custom.cpp b/implementation/e2e_protection/src/e2e/profile/profile_custom/profile_custom.cpp
new file mode 100644
index 0000000..d7de34b
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile_custom/profile_custom.cpp
@@ -0,0 +1,28 @@
+// 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 "../../../../../e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp"
+#include "../../../../../e2e_protection/include/crc/crc.hpp"
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <iomanip>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_custom {
+
+uint32_t profile_custom::compute_crc(const profile_config &_config, const e2e_buffer &_buffer) {
+ uint32_t computed_crc = e2e_crc::calculate_profile_custom(buffer_view(_buffer, _config.crc_offset_ + 4, _buffer.size()));
+ return computed_crc;
+}
+
+bool profile_custom::is_buffer_length_valid(const profile_config &_config, const e2e_buffer &_buffer) {
+ return ((_config.crc_offset_ + 4U) <=_buffer.size());
+}
+
+} // namespace profile_custom
+} // namespace e2e
+} // namespace vsomeip
diff --git a/implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp b/implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp
new file mode 100644
index 0000000..f061e55
--- /dev/null
+++ b/implementation/e2e_protection/src/e2e/profile/profile_custom/protector.cpp
@@ -0,0 +1,40 @@
+// 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 "../../../../../e2e_protection/include/e2e/profile/profile_custom/protector.hpp"
+#include "../../../../../logging/include/logger.hpp"
+
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+
+namespace vsomeip {
+namespace e2e {
+namespace profile_custom {
+
+void protector::protect(e2e_buffer &_buffer) {
+ std::lock_guard<std::mutex> lock(protect_mutex_);
+
+ if (profile_custom::is_buffer_length_valid(config_, _buffer)) {
+ // compute the CRC over DataID and Data
+ uint32_t computed_crc = profile_custom::compute_crc(config_, _buffer);
+ // write CRC in Data
+ write_crc(_buffer, computed_crc);
+ }
+}
+
+void protector::write_crc(e2e_buffer &_buffer, uint32_t _computed_crc) {
+ _buffer[config_.crc_offset_] = static_cast<uint8_t>(_computed_crc >> 24U);
+ _buffer[config_.crc_offset_ + 1U] = static_cast<uint8_t>(_computed_crc >> 16U);
+ _buffer[config_.crc_offset_ + 2U] = static_cast<uint8_t>(_computed_crc >> 8U);
+ _buffer[config_.crc_offset_ + 3U] = static_cast<uint8_t>(_computed_crc);
+}
+
+} // namespace profile_custom
+} // namespace e2e
+} // namespace vsomeip
diff --git a/implementation/e2e_protection/src/e2exf/config.cpp b/implementation/e2e_protection/src/e2exf/config.cpp
new file mode 100644
index 0000000..e210faf
--- /dev/null
+++ b/implementation/e2e_protection/src/e2exf/config.cpp
@@ -0,0 +1,16 @@
+// 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 <ostream>
+#include "../../../e2e_protection/include/e2exf/config.hpp"
+
+namespace vsomeip {
+
+std::ostream &operator<<(std::ostream &_os, const e2exf::data_identifier &_data_identifier) {
+ _os << _data_identifier.first << _data_identifier.second;
+ return _os;
+}
+
+} // namespace vsomeip