diff options
Diffstat (limited to 'interface/vsomeip')
24 files changed, 590 insertions, 105 deletions
diff --git a/interface/vsomeip/application.hpp b/interface/vsomeip/application.hpp index 366ecf1..10ead3e 100644 --- a/interface/vsomeip/application.hpp +++ b/interface/vsomeip/application.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -12,14 +12,17 @@ #include <map> #include <vector> +#include <vsomeip/deprecated.hpp> #include <vsomeip/primitive_types.hpp> #include <vsomeip/enumeration_types.hpp> +#include <vsomeip/structured_types.hpp> #include <vsomeip/function_types.hpp> #include <vsomeip/constants.hpp> #include <vsomeip/handler.hpp> namespace vsomeip_v3 { +class configuration; class configuration_public; class event; class payload; @@ -475,7 +478,7 @@ public: * \param _handler Handler function to be called on state change. * */ - virtual void register_state_handler(state_handler_t _handler) = 0; + virtual void register_state_handler(const state_handler_t &_handler) = 0; /** * @@ -517,7 +520,7 @@ public: */ virtual void register_message_handler(service_t _service, instance_t _instance, method_t _method, - message_handler_t _handler) = 0; + const message_handler_t &_handler) = 0; /** * * \brief Unregisters the message handler for the specified service @@ -559,7 +562,7 @@ public: * */ virtual void register_availability_handler(service_t _service, - instance_t _instance, availability_handler_t _handler, + instance_t _instance, const availability_handler_t &_handler, major_version_t _major = ANY_MAJOR, minor_version_t _minor = ANY_MINOR) = 0; /** @@ -599,35 +602,37 @@ public: * handler decides if the subscription is accepted or not. * */ + VSOMEIP_DEPRECATED_UID_GID virtual void register_subscription_handler(service_t _service, instance_t _instance, eventgroup_t _eventgroup, - subscription_handler_t _handler) = 0; - - /** - * - * \brief Registers an async subscription handler. - * - * A subscription handler is called whenever the subscription state of an - * eventgroup changes. The callback is called with the client identifier - * and a boolean that indicates whether the client subscribed or - * unsubscribed. - * This method offers the possibility to asynchronously accept/rejects - * subscriptions through a callback. - * - * \param _service Service identifier of service instance whose - * subscription state is to be monitored. - * \param _instance Instance identifier of service instance whose - * subscription state is to be monitored. - * \param _eventgroup Eventgroup identifier of eventgroup whose - * subscription state is to be monitored. - * \param _handler Callback that shall be called. The value passed to the - * callback passed as a parameter to this handler decides if the - * subscription is accepted or not. - * - */ - virtual void register_async_subscription_handler( - service_t _service, instance_t _instance, eventgroup_t _eventgroup, - async_subscription_handler_t _handler) = 0; + const subscription_handler_t &_handler) = 0; + + /** + * + * \brief Registers an async subscription handler. + * + * A subscription handler is called whenever the subscription state of an + * eventgroup changes. The callback is called with the client identifier + * and a boolean that indicates whether the client subscribed or + * unsubscribed. + * This method offers the possibility to asynchronously accept/rejects + * subscriptions through a callback. + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * \param _handler Callback that shall be called. The value passed to the + * callback passed as a parameter to this handler decides if the + * subscription is accepted or not. + * + */ + VSOMEIP_DEPRECATED_UID_GID + virtual void register_async_subscription_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup, + const async_subscription_handler_t &_handler) = 0; /** * @@ -742,7 +747,7 @@ public: * \param _offer_type type of offered services to be returned (OT_LOCAL = 0x00, OT_REMOTE = 0x01, OT_ALL = 0x02) * \param offered_services_handler_t handler which gets called with a vector of service instance pairs that are currently offered */ - virtual void get_offered_services_async(offer_type_e _offer_type, offered_services_handler_t _handler) = 0; + virtual void get_offered_services_async(offer_type_e _offer_type, const offered_services_handler_t &_handler) = 0; /** * @@ -769,7 +774,7 @@ public: * \param _handler A watchdog handler, pass nullptr to deactivate. * \param _interval Call interval in seconds, pass std::chrono::seconds::zero() to deactivate. */ - virtual void set_watchdog_handler(watchdog_handler_t _handler, std::chrono::seconds _interval) = 0; + virtual void set_watchdog_handler(const watchdog_handler_t &_handler, std::chrono::seconds _interval) = 0; /** * \brief Enables or disables calling of registered acceptance @@ -784,8 +789,8 @@ public: * \param _enable enable or disable calling of offer acceptance handler */ virtual void set_sd_acceptance_required(const remote_info_t& _remote, - const std::string& _path, - bool _enable) = 0; + const std::string& _path, + bool _enable) = 0; /** * \brief Enables or disables calling of registered acceptance @@ -823,7 +828,7 @@ public: * * \param _handler The handler to be called */ - virtual void register_sd_acceptance_handler(sd_acceptance_handler_t _handler) = 0; + virtual void register_sd_acceptance_handler(const sd_acceptance_handler_t &_handler) = 0; /** * \brief Registers a handler which will be called upon detection of a @@ -835,7 +840,7 @@ public: * \param _handler The handler to be called */ virtual void register_reboot_notification_handler( - reboot_notification_handler_t _handler) = 0; + const reboot_notification_handler_t &_handler) = 0; /** * \brief Registers a handler which will be called when the routing reached @@ -847,7 +852,7 @@ public: * \param _handler The handler to be called */ virtual void register_routing_ready_handler( - routing_ready_handler_t _handler) = 0; + const routing_ready_handler_t &_handler) = 0; /** * \brief Registers a handler which will be called when the routing state @@ -859,7 +864,7 @@ public: * \param _handler The handler to be called */ virtual void register_routing_state_handler( - routing_state_handler_t _handler) = 0; + const routing_state_handler_t &_handler) = 0; /** * \brief Update service configuration to offer a local service on the @@ -903,7 +908,7 @@ public: uint32_t _gid, std::shared_ptr<policy> _policy, std::shared_ptr<payload> _payload, - security_update_handler_t _handler) = 0; + const security_update_handler_t &_handler) = 0; /** * \brief Remove a security configuration for routing manager and all local clients @@ -919,7 +924,186 @@ public: */ virtual void remove_security_policy_configuration(uint32_t _uid, uint32_t _gid, - security_update_handler_t _handler) = 0; + const security_update_handler_t &_handler) = 0; + + /** + * + * \brief Registers a subscription handler. + * + * A subscription handler is called whenever the subscription state of an + * eventgroup changes. The callback is called with the client identifier + * and a boolean that indicates whether the client subscribed or + * unsubscribed. + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * \param _handler Callback that shall be called. The value returned by this + * handler decides if the subscription is accepted or not. + * + */ + VSOMEIP_DEPRECATED_UID_GID + virtual void register_subscription_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, + const subscription_handler_ext_t &_handler) = 0; + + /** + * + * \brief Registers an async subscription handler. + * + * A subscription handler is called whenever the subscription state of an + * eventgroup changes. The callback is called with the client identifier + * and a boolean that indicates whether the client subscribed or + * unsubscribed. + * This method offers the possibility to asynchronously accept/rejects + * subscriptions through a callback. + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * \param _handler Callback that shall be called. The value passed to the + * callback passed as a parameter to this handler decides if the + * subscription is accepted or not. + * + */ + VSOMEIP_DEPRECATED_UID_GID + virtual void register_async_subscription_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup, + const async_subscription_handler_ext_t &_handler) = 0; + + + /** + * + * \brief Subscribes to an eventgroup. + * + * A user application must call this function to subscribe to an eventgroup. + * Before calling subscribe it must register all events it interested in by + * calls to @ref request_event. The method additionally allows to specify + * a specific event. If a specific event is specified, all other events of + * the eventgroup are not received by the application. + * + * Note: For external services, providing a specific event does not change + * anything regarding the message routing. The specific event is only used + * to filter incoming events and to determine which initial events must be + * sent. + * + * \param _service Service identifier of the service that contains the + * eventgroup. + * \param _instance Instance identifier of the service that contains the + * eventgroup. + * \param _eventgroup Eventgroup identifier of the eventgroup. + * \param _major Major version number of the service. + * \param _event All (Default) or a specific event. + * \param _filter Filter configuration to decide whether or not an + * incoming event will be forwarded to the application. + */ + virtual void subscribe_with_debounce(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, major_version_t _major, + event_t _event, const debounce_filter_t &_filter) = 0; + + /** + * \brief Registers a handler which will be called upon reception of + * a remote VSOMEIP/SD message with the sending ECU's IP address and port as + * parameter + * + * This method has only an effect when called on the application acting as + * routing manager + * + * \param _handler The handler to be called + */ + virtual void register_message_acceptance_handler(const message_acceptance_handler_t &_handler) = 0; + + /** + * \brief Get the configuration additional data of an application plugin + * + * \return The configuration additional data of an application plugin + */ + virtual std::map<std::string, std::string> get_additional_data( + const std::string &_plugin_name) = 0; + + + /** + * + * \brief Register a callback that is called when service instances + * availability (state) changes. + * + * This method allows for the registration of callbacks that are called + * whenever a service appears or disappears. It is possible to specify + * wildcards for service, instance and/or version. Additionally, the + * version specification is optional and defaults to DEFAULT_MAJOR + * /DEFAULT_MINOR. + * + * \param _service Service identifier of the service instance whose + * availability shall be reported. Can be set to ANY_SERVICE. + * \param _instance Instance identifier of the service instance whose + * availability shall be reported. Can be set to ANY_INSTANCE. + * \param _handler Callback to be called if availability (state) changes. + * \param _major Major service version. The parameter defaults to + * DEFAULT_MAJOR and can be set to ANY_MAJOR. + * \param _minor Minor service version. The parameter defaults to + * DEFAULT_MINOR and can be set to ANY_MINOR. + * + */ + virtual void register_availability_handler(service_t _service, + instance_t _instance, const availability_state_handler_t &_handler, + major_version_t _major = ANY_MAJOR, minor_version_t _minor = ANY_MINOR) = 0; + + /** + * + * \brief Registers a subscription handler. + * + * A subscription handler is called whenever the subscription state of an + * eventgroup changes. The callback is called with the client identifier + * and a boolean that indicates whether the client subscribed or + * unsubscribed. + * (vsomeip_sec_client_t-aware) + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * \param _handler Callback that shall be called. The value returned by this + * handler decides if the subscription is accepted or not. + * + */ + virtual void register_subscription_handler(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, + const subscription_handler_sec_t &_handler) = 0; + + /** + * + * \brief Registers an async subscription handler. + * + * A subscription handler is called whenever the subscription state of an + * eventgroup changes. The callback is called with the client identifier + * and a boolean that indicates whether the client subscribed or + * unsubscribed. + * This method offers the possibility to asynchronously accept/rejects + * subscriptions through a callback. + * (vsomeip_sec_client_t-aware) + * + * \param _service Service identifier of service instance whose + * subscription state is to be monitored. + * \param _instance Instance identifier of service instance whose + * subscription state is to be monitored. + * \param _eventgroup Eventgroup identifier of eventgroup whose + * subscription state is to be monitored. + * \param _handler Callback that shall be called. The value passed to the + * callback passed as a parameter to this handler decides if the + * subscription is accepted or not. + * + */ + virtual void register_async_subscription_handler( + service_t _service, instance_t _instance, eventgroup_t _eventgroup, + async_subscription_handler_sec_t _handler) = 0; }; /** @} */ diff --git a/interface/vsomeip/constants.hpp b/interface/vsomeip/constants.hpp index 3a8201a..2b040c5 100644 --- a/interface/vsomeip/constants.hpp +++ b/interface/vsomeip/constants.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -19,13 +19,14 @@ const ttl_t DEFAULT_TTL = 0xFFFFFF; // "until next reboot" const std::string DEFAULT_MULTICAST = "224.0.0.0"; const uint16_t DEFAULT_PORT = 30500; -const uint16_t ILLEGAL_PORT = 0; +const uint16_t ILLEGAL_PORT = 0xFFFF; const uint16_t ANY_PORT = 0; const uint16_t NO_TRACE_FILTER_EXPRESSION = 0x0000; const service_t ANY_SERVICE = 0xFFFF; const instance_t ANY_INSTANCE = 0xFFFF; +const eventgroup_t ANY_EVENTGROUP = 0xFFFF; const method_t ANY_METHOD = 0xFFFF; const major_version_t ANY_MAJOR = 0xFF; const minor_version_t ANY_MINOR = 0xFFFFFFFF; diff --git a/interface/vsomeip/defines.hpp b/interface/vsomeip/defines.hpp index e10c453..6485380 100644 --- a/interface/vsomeip/defines.hpp +++ b/interface/vsomeip/defines.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2023 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/. @@ -6,36 +6,39 @@ #ifndef VSOMEIP_V3_DEFINES_HPP_ #define VSOMEIP_V3_DEFINES_HPP_ -#define VSOMEIP_PROTOCOL_VERSION 0x1 +#include <cstddef> +#include <cstdint> + +constexpr std::uint8_t VSOMEIP_PROTOCOL_VERSION = 0x1; // 0 = unlimited, if not specified otherwise via configuration file -#define VSOMEIP_MAX_LOCAL_MESSAGE_SIZE 0 +constexpr std::size_t VSOMEIP_MAX_LOCAL_MESSAGE_SIZE = 0; // 0 = unlimited, if not specified otherwise via configuration file -#define VSOMEIP_MAX_TCP_MESSAGE_SIZE 0 -#define VSOMEIP_MAX_UDP_MESSAGE_SIZE 1416 - -#define VSOMEIP_PACKET_SIZE VSOMEIP_MAX_UDP_MESSAGE_SIZE - -#define VSOMEIP_SOMEIP_HEADER_SIZE 8 -#define VSOMEIP_SOMEIP_MAGIC_COOKIE_SIZE 8 -#define VSOMEIP_FULL_HEADER_SIZE 16 - -#define VSOMEIP_SERVICE_POS_MIN 0 -#define VSOMEIP_SERVICE_POS_MAX 1 -#define VSOMEIP_METHOD_POS_MIN 2 -#define VSOMEIP_METHOD_POS_MAX 3 -#define VSOMEIP_EVENT_POS_MIN 2 -#define VSOMEIP_EVENT_POS_MAX 3 -#define VSOMEIP_LENGTH_POS_MIN 4 -#define VSOMEIP_LENGTH_POS_MAX 7 -#define VSOMEIP_CLIENT_POS_MIN 8 -#define VSOMEIP_CLIENT_POS_MAX 9 -#define VSOMEIP_SESSION_POS_MIN 10 -#define VSOMEIP_SESSION_POS_MAX 11 -#define VSOMEIP_PROTOCOL_VERSION_POS 12 -#define VSOMEIP_INTERFACE_VERSION_POS 13 -#define VSOMEIP_MESSAGE_TYPE_POS 14 -#define VSOMEIP_RETURN_CODE_POS 15 -#define VSOMEIP_PAYLOAD_POS 16 +constexpr std::size_t VSOMEIP_MAX_TCP_MESSAGE_SIZE = 0; +constexpr std::size_t VSOMEIP_MAX_UDP_MESSAGE_SIZE = 1416; + +constexpr std::size_t VSOMEIP_PACKET_SIZE = VSOMEIP_MAX_UDP_MESSAGE_SIZE; + +constexpr std::size_t VSOMEIP_SOMEIP_MAGIC_COOKIE_SIZE = 8; +constexpr std::uint32_t VSOMEIP_SOMEIP_HEADER_SIZE = 8; +constexpr std::uint32_t VSOMEIP_FULL_HEADER_SIZE = 16; + +constexpr std::size_t VSOMEIP_SERVICE_POS_MIN = 0; +constexpr std::size_t VSOMEIP_SERVICE_POS_MAX = 1; +constexpr std::size_t VSOMEIP_METHOD_POS_MIN = 2; +constexpr std::size_t VSOMEIP_METHOD_POS_MAX = 3; +constexpr std::size_t VSOMEIP_EVENT_POS_MIN = 2; +constexpr std::size_t VSOMEIP_EVENT_POS_MAX = 3; +constexpr std::size_t VSOMEIP_LENGTH_POS_MIN = 4; +constexpr std::size_t VSOMEIP_LENGTH_POS_MAX = 7; +constexpr std::size_t VSOMEIP_CLIENT_POS_MIN = 8; +constexpr std::size_t VSOMEIP_CLIENT_POS_MAX = 9; +constexpr std::size_t VSOMEIP_SESSION_POS_MIN = 10; +constexpr std::size_t VSOMEIP_SESSION_POS_MAX = 11; +constexpr std::size_t VSOMEIP_PROTOCOL_VERSION_POS = 12; +constexpr std::size_t VSOMEIP_INTERFACE_VERSION_POS = 13; +constexpr std::size_t VSOMEIP_MESSAGE_TYPE_POS = 14; +constexpr std::size_t VSOMEIP_RETURN_CODE_POS = 15; +constexpr std::size_t VSOMEIP_PAYLOAD_POS = 16; #endif // VSOMEIP_V3_DEFINES_HPP_ diff --git a/interface/vsomeip/deprecated.hpp b/interface/vsomeip/deprecated.hpp new file mode 100644 index 0000000..9ba0235 --- /dev/null +++ b/interface/vsomeip/deprecated.hpp @@ -0,0 +1,10 @@ +#ifndef VSOMEIP_V3_DEPRECATED_HPP_ +#define VSOMEIP_V3_DEPRECATED_HPP_ + +#ifdef VSOMEIP_INTERNAL_SUPPRESS_DEPRECATED +#define VSOMEIP_DEPRECATED_UID_GID +#else +#define VSOMEIP_DEPRECATED_UID_GID [[deprecated("Use vsomeip_sec_client_t-aware functions and types instead.")]] +#endif + +#endif // VSOMEIP_V3_DEPRECATED_HPP_ diff --git a/interface/vsomeip/enumeration_types.hpp b/interface/vsomeip/enumeration_types.hpp index a6bc315..8229a89 100644 --- a/interface/vsomeip/enumeration_types.hpp +++ b/interface/vsomeip/enumeration_types.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -88,6 +88,13 @@ enum class reliability_type_e : uint8_t { RT_UNKNOWN = 0xFF }; +enum class availability_state_e : uint8_t { + AS_UNAVAILABLE = 0x00, // unseen + AS_OFFERED = 0x01, // seen, but not requested/not yet usable + AS_AVAILABLE = 0x02, // seen and usable + AS_UNKNOWN = 0xFF +}; + } // namespace vsomeip_v3 #endif // VSOMEIP_V3_ENUMERATION_TYPES_HPP_ diff --git a/interface/vsomeip/error.hpp b/interface/vsomeip/error.hpp index 8415d90..ecbf591 100644 --- a/interface/vsomeip/error.hpp +++ b/interface/vsomeip/error.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. diff --git a/interface/vsomeip/function_types.hpp b/interface/vsomeip/function_types.hpp index 31ef9d5..6103025 100644 --- a/interface/vsomeip/function_types.hpp +++ b/interface/vsomeip/function_types.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2016-2021 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/. diff --git a/interface/vsomeip/handler.hpp b/interface/vsomeip/handler.hpp index 7e2bbe9..f95ed7b 100644 --- a/interface/vsomeip/handler.hpp +++ b/interface/vsomeip/handler.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -10,7 +10,9 @@ #include <memory> #include <tuple> +#include <vsomeip/deprecated.hpp> #include <vsomeip/primitive_types.hpp> +#include <vsomeip/vsomeip_sec.h> namespace vsomeip_v3 { @@ -19,15 +21,26 @@ class message; typedef std::function< void (state_type_e) > state_handler_t; typedef std::function< void (const std::shared_ptr< message > &) > message_handler_t; typedef std::function< void (service_t, instance_t, bool) > availability_handler_t; -typedef std::function< bool (client_t, uid_t, gid_t, bool) > subscription_handler_t; +typedef std::function< void (service_t, instance_t, availability_state_e) > availability_state_handler_t; +VSOMEIP_DEPRECATED_UID_GID typedef std::function< bool (client_t, uid_t, gid_t, bool) > subscription_handler_t; +VSOMEIP_DEPRECATED_UID_GID typedef std::function< bool (client_t, uid_t, gid_t, const std::string &, bool) > subscription_handler_ext_t; typedef std::function< void (const uint16_t) > error_handler_t; typedef std::function< void (const service_t, const instance_t, const eventgroup_t, const event_t, const uint16_t) > subscription_status_handler_t; -typedef std::function< void (client_t, uid_t, gid_t, bool, std::function< void (const bool) > )> async_subscription_handler_t; +VSOMEIP_DEPRECATED_UID_GID typedef std::function< void (client_t, uid_t, gid_t, bool, + std::function< void (const bool) > )> async_subscription_handler_t; +VSOMEIP_DEPRECATED_UID_GID typedef std::function< void (client_t, uid_t, gid_t, const std::string &, bool, + std::function< void (const bool) > )> async_subscription_handler_ext_t; typedef std::function< void (const std::vector<std::pair<service_t, instance_t>> &_services) > offered_services_handler_t; typedef std::function< void () > watchdog_handler_t; +/* + * vsomeip_sec_client_t-aware subscription handlers + */ +using subscription_handler_sec_t = std::function<bool(client_t, const vsomeip_sec_client_t*, const std::string&, bool)>; +using async_subscription_handler_sec_t = std::function<void(client_t, const vsomeip_sec_client_t*, const std::string&, bool, std::function<void(bool)>)>; + struct ip_address_t { union { ipv4_address_t v4_; @@ -77,11 +90,20 @@ struct remote_info_t { } }; +struct message_acceptance_t { + std::uint32_t remote_address_; + std::uint16_t local_port_; + bool is_local_; + service_t service_; + instance_t instance_; +}; + typedef std::function<bool(const remote_info_t&)> sd_acceptance_handler_t; typedef std::function<void(const ip_address_t&)> reboot_notification_handler_t; typedef std::function<void()> routing_ready_handler_t; typedef std::function<void(routing_state_e)> routing_state_handler_t; typedef std::function<void(security_update_state_e)> security_update_handler_t; +typedef std::function<bool(const message_acceptance_t&)> message_acceptance_handler_t; } // namespace vsomeip_v3 diff --git a/interface/vsomeip/internal/deserializable.hpp b/interface/vsomeip/internal/deserializable.hpp index ae661e5..b2a549e 100644 --- a/interface/vsomeip/internal/deserializable.hpp +++ b/interface/vsomeip/internal/deserializable.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. diff --git a/interface/vsomeip/internal/logger.hpp b/interface/vsomeip/internal/logger.hpp index db92b86..4d1f4b6 100644 --- a/interface/vsomeip/internal/logger.hpp +++ b/interface/vsomeip/internal/logger.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2020-2021 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/. diff --git a/interface/vsomeip/internal/policy_manager.hpp b/interface/vsomeip/internal/policy_manager.hpp index 45756ec..0d610d9 100644 --- a/interface/vsomeip/internal/policy_manager.hpp +++ b/interface/vsomeip/internal/policy_manager.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2019-2021 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/. @@ -6,15 +6,18 @@ #ifndef VSOMEIP_V3_POLICY_MANAGER_HPP_ #define VSOMEIP_V3_POLICY_MANAGER_HPP_ + #include <memory> +#include <vsomeip/deprecated.hpp> +#include <vsomeip/export.hpp> #include <vsomeip/primitive_types.hpp> namespace vsomeip_v3 { struct policy; -class policy_manager { +class VSOMEIP_IMPORT_EXPORT policy_manager { public: static std::shared_ptr<policy_manager> get(); @@ -35,4 +38,5 @@ public: } // namespace vsomeip_v3 + #endif // VSOMEIP_V3_POLICY_MANAGER_HPP_ diff --git a/interface/vsomeip/internal/serializable.hpp b/interface/vsomeip/internal/serializable.hpp index 52540b8..8101e52 100644 --- a/interface/vsomeip/internal/serializable.hpp +++ b/interface/vsomeip/internal/serializable.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. diff --git a/interface/vsomeip/message.hpp b/interface/vsomeip/message.hpp index 0d1c5cc..e7e0b0d 100644 --- a/interface/vsomeip/message.hpp +++ b/interface/vsomeip/message.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -8,7 +8,9 @@ #include <memory> +#include <vsomeip/deprecated.hpp> #include <vsomeip/message_base.hpp> +#include <vsomeip/vsomeip_sec.h> namespace vsomeip_v3 { @@ -62,12 +64,22 @@ public: /** * \brief Return uid of the message sender. */ - VSOMEIP_EXPORT virtual uid_t get_uid() const = 0; + VSOMEIP_DEPRECATED_UID_GID VSOMEIP_EXPORT virtual uid_t get_uid() const = 0; /** * \brief Return gid of the message sender. */ - VSOMEIP_EXPORT virtual gid_t get_gid() const = 0; + VSOMEIP_DEPRECATED_UID_GID VSOMEIP_EXPORT virtual gid_t get_gid() const = 0; + + /** + * \brief Return environment (hostname) of the message sender. + */ + VSOMEIP_EXPORT virtual std::string get_env() const = 0; + + /** + * \brief Return security client of the message sender. + */ + VSOMEIP_EXPORT virtual vsomeip_sec_client_t get_sec_client() const = 0; }; /** @} */ diff --git a/interface/vsomeip/message_base.hpp b/interface/vsomeip/message_base.hpp index b6efa8b..fbdceb7 100644 --- a/interface/vsomeip/message_base.hpp +++ b/interface/vsomeip/message_base.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. diff --git a/interface/vsomeip/payload.hpp b/interface/vsomeip/payload.hpp index 3e7e45a..9b8ea95 100644 --- a/interface/vsomeip/payload.hpp +++ b/interface/vsomeip/payload.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. diff --git a/interface/vsomeip/plugin.hpp b/interface/vsomeip/plugin.hpp index 33667a8..25ccbb2 100644 --- a/interface/vsomeip/plugin.hpp +++ b/interface/vsomeip/plugin.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2016-2021 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/. @@ -39,12 +39,7 @@ typedef create_plugin_func (*plugin_init_func)(); */ class VSOMEIP_IMPORT_EXPORT_PLUGIN plugin { public: - virtual ~plugin() -#ifndef ANDROID - {} -#else - ; -#endif + virtual ~plugin() {} virtual uint32_t get_plugin_version() const = 0; virtual const std::string &get_plugin_name() const = 0; @@ -65,15 +60,15 @@ public: type_ = _type; } - const std::string &get_plugin_name() const override { + const std::string &get_plugin_name() const { return name_; } - uint32_t get_plugin_version() const override { + uint32_t get_plugin_version() const { return version_; } - plugin_type_e get_plugin_type() const override { + plugin_type_e get_plugin_type() const { return type_; } diff --git a/interface/vsomeip/plugins/application_plugin.hpp b/interface/vsomeip/plugins/application_plugin.hpp index 90e3e64..a052aa2 100644 --- a/interface/vsomeip/plugins/application_plugin.hpp +++ b/interface/vsomeip/plugins/application_plugin.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2016-2021 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/. diff --git a/interface/vsomeip/plugins/pre_configuration_plugin.hpp b/interface/vsomeip/plugins/pre_configuration_plugin.hpp index 6505249..5385993 100644 --- a/interface/vsomeip/plugins/pre_configuration_plugin.hpp +++ b/interface/vsomeip/plugins/pre_configuration_plugin.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2016-2021 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/. diff --git a/interface/vsomeip/primitive_types.hpp b/interface/vsomeip/primitive_types.hpp index 26a9fd7..0a9eaa5 100644 --- a/interface/vsomeip/primitive_types.hpp +++ b/interface/vsomeip/primitive_types.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -10,7 +10,7 @@ #include <cstdint> #include <string> -#ifndef _WIN32 +#if defined(__linux__) || defined(ANDROID) #include <sys/types.h> #endif @@ -41,9 +41,12 @@ typedef uint8_t interface_version_t; typedef uint8_t byte_t; typedef uint16_t diagnosis_t; +typedef uint16_t port_t; + // Addresses typedef std::array<byte_t, 4> ipv4_address_t; typedef std::array<byte_t, 16> ipv6_address_t; +typedef std::uint16_t port_t; typedef std::string trace_channel_t; diff --git a/interface/vsomeip/runtime.hpp b/interface/vsomeip/runtime.hpp index 513847d..e2d97c8 100644 --- a/interface/vsomeip/runtime.hpp +++ b/interface/vsomeip/runtime.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. @@ -207,6 +207,26 @@ public: * */ virtual void remove_application( const std::string &_name) = 0; + + /** + * + * \brief Creates a vsomeip application object. + * + * An application object manages service offers and requests as well as + * event subscriptions. It allows to register user application functions + * as callbacks that are called on specific events during runtime, e.g + * to react on incoming SOME/IP messages. + * An application object is identified by a unique name that is also used + * in (and therefore has to match) the configuration files of vsomeip. If + * the name is left empty, the application name is taken from the + * environment variable "VSOMEIP_APPLICATION_NAME" + * + * \param _name Name of the application on the system. + * \param _path Path to the configuration file or folder. + * + */ + virtual std::shared_ptr<application> create_application( + const std::string &_name, const std::string &_path) = 0; }; /** @} */ diff --git a/interface/vsomeip/structured_types.hpp b/interface/vsomeip/structured_types.hpp new file mode 100644 index 0000000..059d33c --- /dev/null +++ b/interface/vsomeip/structured_types.hpp @@ -0,0 +1,66 @@ +// Copyright (C) 2021 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_STRUCTURED_TYPES_HPP_ +#define VSOMEIP_V3_STRUCTURED_TYPES_HPP_ + +#include <chrono> +#include <map> + +namespace vsomeip_v3 { + +// Messages are forwarded either because their value differs from the +// last received message (on_change) or because the specified time +// (interval) between two messages has elapsed. A message that is forwarded +// because of a changed value may reset the time until the next unchanged +// message is forwarded or not (on_change_resets_interval). By specifiying +// indexes and bit masks, the comparison that is carried out to decide whether +// or not two message values differ is configurable (ignore). +struct debounce_filter_t { + debounce_filter_t() + : on_change_(false), + on_change_resets_interval_(false), + interval_(-1) { + } + + debounce_filter_t(const debounce_filter_t &_source) + : on_change_(_source.on_change_), + on_change_resets_interval_(_source.on_change_resets_interval_), + interval_(_source.interval_), + ignore_(_source.ignore_) { + } + + inline void operator=(const debounce_filter_t &_other) { + on_change_ = _other.on_change_; + on_change_resets_interval_ = _other.on_change_resets_interval_; + interval_ = _other.interval_; + ignore_ = _other.ignore_; + } + + inline bool operator==(const debounce_filter_t &_other) const { + + return (on_change_ == _other.on_change_ + && on_change_resets_interval_ == _other.on_change_resets_interval_ + && interval_ == _other.interval_ + && ignore_ == _other.ignore_); + } + + inline bool operator!=(const debounce_filter_t &_other) const { + + return (on_change_ != _other.on_change_ + || on_change_resets_interval_ != _other.on_change_resets_interval_ + || interval_ != _other.interval_ + || ignore_ != _other.ignore_); + } + + bool on_change_; + bool on_change_resets_interval_; + int64_t interval_; + std::map<std::size_t, byte_t> ignore_; +}; + +} // namespace vsomeip_v3 + +#endif // VSOMEIP_V3_STRUCTURED_TYPES_HPP diff --git a/interface/vsomeip/trace.hpp b/interface/vsomeip/trace.hpp index cf5b7b9..016dc5a 100644 --- a/interface/vsomeip/trace.hpp +++ b/interface/vsomeip/trace.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2017-2021 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/. diff --git a/interface/vsomeip/vsomeip.hpp b/interface/vsomeip/vsomeip.hpp index 231fa3a..f0a66c5 100644 --- a/interface/vsomeip/vsomeip.hpp +++ b/interface/vsomeip/vsomeip.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 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/. diff --git a/interface/vsomeip/vsomeip_sec.h b/interface/vsomeip/vsomeip_sec.h new file mode 100644 index 0000000..88c3666 --- /dev/null +++ b/interface/vsomeip/vsomeip_sec.h @@ -0,0 +1,158 @@ +// Copyright (C) 2022 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_SECURITY_VSOMEIP_SEC_H_ +#define VSOMEIP_V3_SECURITY_VSOMEIP_SEC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> +#include <sys/types.h> + +typedef uint16_t vsomeip_sec_service_id_t; +typedef uint16_t vsomeip_sec_instance_id_t; +typedef uint16_t vsomeip_sec_member_id_t; // SOME/IP method or event + +typedef uint32_t vsomeip_sec_ip_addr_t; // ip address in network byte order +typedef uint16_t vsomeip_sec_network_port_t; // network port in network byte order + +#ifndef __unix__ +typedef uint32_t uid_t; +typedef uint32_t gid_t; +#endif + +typedef struct { + uid_t user; + gid_t group; +} vsomeip_sec_uds_client_credentials_t; + +typedef struct { + vsomeip_sec_ip_addr_t ip; + vsomeip_sec_network_port_t port; +} vsomeip_sec_ip_client_credentials_t; + +typedef enum { + VSOMEIP_CLIENT_UDS, + VSOMEIP_CLIENT_TCP, + VSOMEIP_CLIENT_INVALID +} vsomeip_sec_client_type_t; + +typedef struct { + vsomeip_sec_client_type_t client_type; + union { + vsomeip_sec_uds_client_credentials_t uds_client; + vsomeip_sec_ip_client_credentials_t ip_client; + } client; +} vsomeip_sec_client_t; + +typedef enum { + VSOMEIP_SEC_OK, + VSOMEIP_SEC_PERM_DENIED +} vsomeip_sec_acl_result_t; + +typedef enum { + VSOMEIP_SEC_POLICY_OK, + VSOMEIP_SEC_POLICY_NOT_FOUND, + VSOMEIP_SEC_POLICY_INVALID +} vsomeip_sec_policy_result_t; + +/** + * Load the policy and initialize policy plugin functionality. + * This function MUST be called before any other function in this library can be called. + * It will return whether loading the policy was successful or if there was some problem + * during initialization. + * + * Please note that the policy initializer does not take any additional arguments. It is assumed + * here tha the policy plugin libraries have some out-of-bounds methods to, e.g., find the policy + * file. + * + * The function may be called multiple times (even from multiple threads) without problems. + */ + vsomeip_sec_policy_result_t vsomeip_sec_policy_initialize(); + +/** + * Authenticate connection with vSomeIP router. + * + * vSomeIP router (vsomeipd) has by definition unlimited access to other vSomeIP applications. + * Therefore, EVERY connection with the router must be authenticated and then any command from/to + * vsomeipd is implicitly allowed. + * + * This method MUST be called to ensure that the remote end is supposed to act as + * vSomeIP routing manager. + * + */ +vsomeip_sec_acl_result_t vsomeip_sec_policy_authenticate_router(const vsomeip_sec_client_t *router); + + +/* + * ### RPC + */ + +/** + * Check if a server is authorised to offer a specific service / instance + * + * vsomeip_sec_policy_is_client_allowed_to_offer checks if \p server is allowed to offer a \p + * service by the security policy. + * + * This API MUST be called by vSomeIP clients before sending requests and before + * processing responses. It and SHOULD be called at the router for every service offer before + * distributing it among the clients. + * + * @note + * Both, method calls and subscribe-notify communications are end-to-end + * authenticated. Therefore, authentication of the server at the router side is optional but + * recommended. Doing so would help to detect system missconfiguration and simplify + * application debugging. + * + * @note + * Due to asynchronous nature of SOME/IP method calls, to deliver a method response, server + * establishes a separate socket which destination client must be authenticated. This method + * does exactly that. + * + * @note + * While client access may be restricted to certain methods or events, servers are always + * allowed to offer. + */ +vsomeip_sec_acl_result_t vsomeip_sec_policy_is_client_allowed_to_offer( + const vsomeip_sec_client_t *server, + vsomeip_sec_service_id_t service, vsomeip_sec_instance_id_t instance); + + + +/** + * Check if client is allowed to request a service. + * + * This method MUST be called at the server/stub side before serving a client request. It may + * additionally be used by vsomeipd when servicing service discovery so that clients that do not + * have the permission to request a certain service cannot (even) successfully discover it. + * + */ +vsomeip_sec_acl_result_t vsomeip_sec_policy_is_client_allowed_to_request( + const vsomeip_sec_client_t *client, + vsomeip_sec_service_id_t service, vsomeip_sec_instance_id_t instance); + + +/** + * Check if client is allowed to access a specific SOME/IP method. + * + * SOME/IP does not really distinguish between methods and events. It just handles everything + * via a uint16 member identifier. The identifiers below 0x7FFF are used for methods, identifier + * starting at 0x8000 are used for events. So we just have one method to check if the client is + * allowed to interact with a specific member. + * + * This method MUST be called at the server/stub side before processing a request that triggers + * a specific method or completes event registration. + */ +vsomeip_sec_acl_result_t vsomeip_sec_policy_is_client_allowed_to_access_member( + const vsomeip_sec_client_t *client, + vsomeip_sec_service_id_t service, vsomeip_sec_instance_id_t instance, vsomeip_sec_member_id_t member); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // VSOMEIP_V3_SECURITY_VSOMEIP_SEC_H_ |