diff options
Diffstat (limited to 'implementation/e2e_protection/include/e2e')
14 files changed, 225 insertions, 46 deletions
diff --git a/implementation/e2e_protection/include/e2e/profile/e2e_provider.hpp b/implementation/e2e_protection/include/e2e/profile/e2e_provider.hpp index aa45829..41d7487 100644 --- a/implementation/e2e_protection/include/e2e/profile/e2e_provider.hpp +++ b/implementation/e2e_protection/include/e2e/profile/e2e_provider.hpp @@ -24,9 +24,13 @@ public: virtual bool is_protected(e2exf::data_identifier_t id) const = 0; virtual bool is_checked(e2exf::data_identifier_t id) const = 0; - virtual void protect(e2exf::data_identifier_t id, e2e_buffer &_buffer) = 0; - virtual void check(e2exf::data_identifier_t id, const e2e_buffer &_buffer, - e2e::profile_interface::check_status_t &_generic_check_status) = 0; + virtual std::size_t get_protection_base(e2exf::data_identifier_t _id) const = 0; + + virtual void protect(e2exf::data_identifier_t id, + e2e_buffer &_buffer, instance_t _instance) = 0; + virtual void check(e2exf::data_identifier_t id, + const e2e_buffer &_buffer, instance_t _instance, + e2e::profile_interface::check_status_t &_generic_check_status) = 0; }; } // namespace e2e diff --git a/implementation/e2e_protection/include/e2e/profile/e2e_provider_impl.hpp b/implementation/e2e_protection/include/e2e/profile/e2e_provider_impl.hpp index b7d41a6..62db2e2 100644 --- a/implementation/e2e_protection/include/e2e/profile/e2e_provider_impl.hpp +++ b/implementation/e2e_protection/include/e2e/profile/e2e_provider_impl.hpp @@ -32,13 +32,18 @@ public: VSOMEIP_EXPORT bool is_protected(e2exf::data_identifier_t id) const override; VSOMEIP_EXPORT bool is_checked(e2exf::data_identifier_t id) const override; - VSOMEIP_EXPORT void protect(e2exf::data_identifier_t id, e2e_buffer &_buffer) override; - VSOMEIP_EXPORT void check(e2exf::data_identifier_t id, const e2e_buffer &_buffer, - profile_interface::check_status_t &_generic_check_status) override; + VSOMEIP_EXPORT std::size_t get_protection_base(e2exf::data_identifier_t _id) const override; + + VSOMEIP_EXPORT void protect(e2exf::data_identifier_t id, + e2e_buffer &_buffer, instance_t _instance) override; + VSOMEIP_EXPORT void check(e2exf::data_identifier_t id, + const e2e_buffer &_buffer, instance_t _instance, + profile_interface::check_status_t &_generic_check_status) override; private: - std::map<e2exf::data_identifier_t, std::shared_ptr<profile_interface::protector>> custom_protectors; - std::map<e2exf::data_identifier_t, std::shared_ptr<profile_interface::checker>> custom_checkers; + std::map<e2exf::data_identifier_t, std::shared_ptr<profile_interface::protector>> custom_protectors_; + std::map<e2exf::data_identifier_t, std::shared_ptr<profile_interface::checker>> custom_checkers_; + std::map<e2exf::data_identifier_t, std::size_t> custom_bases_; template<typename config_t> config_t make_e2e_profile_config(const std::shared_ptr<cfg::e2e>& config); @@ -50,13 +55,15 @@ private: std::shared_ptr<e2e::profile_interface::checker> checker; if ((config->variant == "checker") || (config->variant == "both")) { - custom_checkers[data_identifier] = std::make_shared<checker_t>(profile_config); + custom_checkers_[data_identifier] = std::make_shared<checker_t>(profile_config); } std::shared_ptr<e2e::profile_interface::protector> protector; if ((config->variant == "protector") || (config->variant == "both")) { - custom_protectors[data_identifier] = std::make_shared<protector_t>(profile_config); + custom_protectors_[data_identifier] = std::make_shared<protector_t>(profile_config); } + + custom_bases_[data_identifier] = profile_config.base_; } }; diff --git a/implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp b/implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp index 3010949..4184996 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile01/checker.hpp @@ -15,15 +15,15 @@ namespace profile01 { class profile_01_checker final : public e2e::profile_interface::checker { - public: +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::check_status_t &_generic_check_status) override final; + void check(const e2e_buffer &_buffer, instance_t _instance, + e2e::profile_interface::check_status_t &_generic_check_status) override final; private: profile_config config_; diff --git a/implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp b/implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp index c6cd5cf..54b2d5c 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile01/profile_01.hpp @@ -7,6 +7,9 @@ #define VSOMEIP_V3_E2E_PROFILE01_PROFILE01_HPP #include <cstdint> + +#include <vsomeip/defines.hpp> + #include "../../../buffer/buffer.hpp" namespace vsomeip_v3 { @@ -26,14 +29,6 @@ class profile_01 { 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, @@ -43,10 +38,22 @@ struct profile_config { : 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) { + data_id_nibble_offset_(_data_id_nibble_offset), + base_(VSOMEIP_FULL_HEADER_SIZE) { } profile_config(const profile_config &_config) = default; profile_config &operator=(const profile_config &_config) = default; + + // [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_; + + // SOME/IP base + size_t base_; }; } // namespace profile01 diff --git a/implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp b/implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp index fe8b603..13bd524 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile01/protector.hpp @@ -7,6 +7,7 @@ #define VSOMEIP_V3_E2E_PROFILE01_PROTECTOR_HPP #include <mutex> + #include "../profile01/profile_01.hpp" #include "../profile_interface/protector.hpp" @@ -15,14 +16,14 @@ namespace e2e { namespace profile01 { class protector final : public e2e::profile_interface::protector { - public: +public: protector(void) = delete; - explicit protector(const profile_config &_config) : config_(_config), counter_(0){}; + explicit protector(const profile_config &_config) : config_(_config), counter_(0) {}; - void protect(e2e_buffer &_buffer) override final; + void protect(e2e_buffer &_buffer, instance_t _instance) override final; - private: +private: void write_counter(e2e_buffer &_buffer); @@ -32,8 +33,7 @@ class protector final : public e2e::profile_interface::protector { void increment_counter(void); - - private: +private: profile_config config_; uint8_t counter_; std::mutex protect_mutex_; diff --git a/implementation/e2e_protection/include/e2e/profile/profile04/checker.hpp b/implementation/e2e_protection/include/e2e/profile/profile04/checker.hpp new file mode 100644 index 0000000..c16eb10 --- /dev/null +++ b/implementation/e2e_protection/include/e2e/profile/profile04/checker.hpp @@ -0,0 +1,45 @@ +// 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/. + +#ifndef VSOMEIP_V3_E2E_PROFILE04_CHECKER_HPP +#define VSOMEIP_V3_E2E_PROFILE04_CHECKER_HPP + +#include "../profile04/profile_04.hpp" +#include "../profile_interface/checker.hpp" + +namespace vsomeip_v3 { +namespace e2e { +namespace profile04 { + +class profile_04_checker final : public e2e::profile_interface::checker { + +public: + profile_04_checker(void) = delete; + + // [SWS_E2E_00389] initialize state + explicit profile_04_checker(const profile_config &_config) : + config_(_config), counter_(0xffff) {} + + void check(const e2e_buffer &_buffer, instance_t _instance, + e2e::profile_interface::check_status_t &_generic_check_status) override final; + +private: + bool verify_input(const e2e_buffer &_buffer) const; + bool verify_counter(uint16_t _received_counter) const; + + bool read_16(const e2e_buffer &_buffer, uint16_t &_data, size_t _index) const; + bool read_32(const e2e_buffer &_buffer, uint32_t &_data, size_t _index) const; + + std::mutex check_mutex_; + + profile_config config_; + uint16_t counter_; +}; + +} // namespace profile_04 +} // namespace e2e +} // namespace vsomeip_v3 + +#endif // VSOMEIP_V3_E2E_PROFILE04_CHECKER_HPP diff --git a/implementation/e2e_protection/include/e2e/profile/profile04/profile_04.hpp b/implementation/e2e_protection/include/e2e/profile/profile04/profile_04.hpp new file mode 100644 index 0000000..88be05c --- /dev/null +++ b/implementation/e2e_protection/include/e2e/profile/profile04/profile_04.hpp @@ -0,0 +1,63 @@ +// 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/. + +#ifndef VSOMEIP_V3_E2E_PROFILE04_PROFILE04_HPP +#define VSOMEIP_V3_E2E_PROFILE04_PROFILE04_HPP + +#include <cstdint> + +#include <vsomeip/defines.hpp> + +#include "../../../buffer/buffer.hpp" + +// The MSB of the dataID is the instance identifier. +// Therefore, the instance identifier must fit into a single byte. +#define VSOMEIP_E2E_PROFILE04_MAX_INSTANCE 0x00ff + +namespace vsomeip_v3 { +namespace e2e { +namespace profile04 { + +struct profile_config; + +class profile_04 { +public: + static uint32_t compute_crc(const profile_config &_config, const e2e_buffer &_buffer); +}; + +// [SWS_E2E_00200] +struct profile_config { + profile_config() = delete; + + profile_config(uint32_t _data_id, size_t _offset, + size_t _min_data_length, size_t _max_data_length, + uint16_t _max_delta_counter) + : data_id_(_data_id), offset_(_offset), + min_data_length_(_min_data_length), max_data_length_(_max_data_length), + max_delta_counter_(_max_delta_counter), + base_(VSOMEIP_SOMEIP_HEADER_SIZE) { + } + profile_config(const profile_config &_config) = default; + profile_config &operator=(const profile_config &_config) = default; + + // [SWS_E2E_00334] + uint32_t data_id_; + size_t offset_; // This must be configured in bit but as a multiple of 8. + // As we must use it as an index, we do the math once at + // configuration time and use the correct data type here. + // Thus, this value is always the byte where the CRC starts. + size_t min_data_length_; + size_t max_data_length_; + uint16_t max_delta_counter_; + + // SOME/IP base + size_t base_; +}; + +} // namespace profile_04 +} // namespace e2e +} // namespace vsomeip_v3 + +#endif // VSOMEIP_V3_E2E_PROFILE04_PROFILE04_HPP diff --git a/implementation/e2e_protection/include/e2e/profile/profile04/protector.hpp b/implementation/e2e_protection/include/e2e/profile/profile04/protector.hpp new file mode 100644 index 0000000..fd4a6e7 --- /dev/null +++ b/implementation/e2e_protection/include/e2e/profile/profile04/protector.hpp @@ -0,0 +1,43 @@ +// 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/. + +#ifndef VSOMEIP_V3_E2E_PROFILE04_PROTECTOR_HPP +#define VSOMEIP_V3_E2E_PROFILE04_PROTECTOR_HPP + +#include <mutex> +#include "../profile04/profile_04.hpp" +#include "../profile_interface/protector.hpp" + +namespace vsomeip_v3 { +namespace e2e { +namespace profile04 { + +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, instance_t _instance) override final; + +private: + bool verify_inputs(e2e_buffer &_buffer); + void increment_counter(); + + void write_16(e2e_buffer &_buffer, uint16_t _data, size_t _index); + void write_32(e2e_buffer &_buffer, uint32_t _data, size_t _index); + +private: + profile_config config_; + uint16_t counter_; + std::mutex protect_mutex_; +}; + +} // namespace profile_04 +} // namespace e2e +} // namespace vsomeip_v3 + +#endif // VSOMEIP_V3_E2E_PROFILE04_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 index 73f1bbb..e233205 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile_custom/checker.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile_custom/checker.hpp @@ -23,10 +23,10 @@ public: explicit profile_custom_checker(const e2e::profile_custom::profile_config &_config) : config_(_config) {} - virtual void check(const e2e_buffer &_buffer, - e2e::profile_interface::check_status_t &_generic_check_status); + void check(const e2e_buffer &_buffer, instance_t _instance, + e2e::profile_interface::check_status_t &_generic_check_status) override final; - private: +private: uint32_t read_crc(const e2e_buffer &_buffer) const; private: 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 index 1cabefa..244989d 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile_custom/profile_custom.hpp @@ -7,6 +7,9 @@ #define VSOMEIP_V3_E2E_PROFILE_CUSTOM_PROFILE_CUSTOM_HPP #include <cstdint> + +#include <vsomeip/defines.hpp> + #include "../../../buffer/buffer.hpp" namespace vsomeip_v3 { @@ -23,15 +26,17 @@ class profile_custom { }; struct profile_config { - uint16_t crc_offset_; - profile_config() = delete; profile_config(uint16_t _crc_offset) - : crc_offset_(_crc_offset) { + : crc_offset_(_crc_offset), + base_(VSOMEIP_FULL_HEADER_SIZE) { } profile_config(const profile_config &_config) = default; profile_config &operator=(const profile_config &_config) = default; + + uint16_t crc_offset_; + size_t base_; }; } // namespace profile_custom diff --git a/implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp b/implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp index 31b976b..a2ec5d1 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile_custom/protector.hpp @@ -15,18 +15,18 @@ namespace e2e { namespace profile_custom { class protector final : public e2e::profile_interface::protector { - public: +public: protector(void) = delete; explicit protector(const profile_config &_config) : config_(_config){}; - void protect(e2e_buffer &_buffer) override final; + void protect(e2e_buffer &_buffer, instance_t _instance) override final; - private: +private: void write_crc(e2e_buffer &_buffer, uint32_t _computed_crc); - private: +private: profile_config config_; std::mutex protect_mutex_; }; diff --git a/implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp b/implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp index f160ea1..12cb6b7 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile_interface/checker.hpp @@ -6,18 +6,21 @@ #ifndef VSOMEIP_V3_E2E_PROFILE_INTERFACE_CHECKER_HPP #define VSOMEIP_V3_E2E_PROFILE_INTERFACE_CHECKER_HPP +#include <mutex> + +#include <vsomeip/primitive_types.hpp> + #include "../profile_interface/profile_interface.hpp" #include "../../../buffer/buffer.hpp" -#include <mutex> namespace vsomeip_v3 { namespace e2e { namespace profile_interface { class checker : public profile_interface { - public: - virtual void check(const e2e_buffer &_buffer, - check_status_t &_generic_check_status) = 0; +public: + virtual void check(const e2e_buffer &_buffer, instance_t _instance, + check_status_t &_generic_check_status) = 0; }; } // namespace profile_interface 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 index dc72aac..5fa018c 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile_interface/profile_interface.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile_interface/profile_interface.hpp @@ -18,8 +18,7 @@ enum generic_check_status : check_status_t { E2E_OK, E2E_WRONG_CRC, E2E_ERROR}; class profile_interface { public: - virtual ~profile_interface() { - } + virtual ~profile_interface() {} }; } // namespace profile_interface diff --git a/implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp b/implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp index 5bae188..4b02971 100644 --- a/implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp +++ b/implementation/e2e_protection/include/e2e/profile/profile_interface/protector.hpp @@ -6,6 +6,8 @@ #ifndef VSOMEIP_V3_E2E_PROFILE_INTERFACE_PROTECTOR_HPP #define VSOMEIP_V3_E2E_PROFILE_INTERFACE_PROTECTOR_HPP +#include <vsomeip/primitive_types.hpp> + #include "../../../buffer/buffer.hpp" #include "../profile_interface/profile_interface.hpp" @@ -14,8 +16,9 @@ namespace e2e { namespace profile_interface { class protector : public profile_interface { - public: - virtual void protect(e2e_buffer &_buffer) = 0; +public: + virtual void protect(e2e_buffer &_buffer, + instance_t _instance) = 0; }; } // namespace profile_interface |