diff options
Diffstat (limited to 'src/components/protocol_handler/include/protocol_handler')
3 files changed, 133 insertions, 15 deletions
diff --git a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h index 0ef40290f2..8b7f28d50e 100644 --- a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h +++ b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h @@ -61,14 +61,14 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { const std::vector<int>& force_protected_service, const bool is_new_service, ProtocolPacket::ProtocolVersion& full_version, - std::shared_ptr<uint8_t> payload); + std::shared_ptr<BsonObject> payload); HandshakeHandler(ProtocolHandlerImpl& protocol_handler, SessionObserver& session_observer, ProtocolPacket::ProtocolVersion& full_version, const SessionContext& context, const uint8_t protocol_version, - std::shared_ptr<uint8_t> payload); + std::shared_ptr<BsonObject> payload); ~HandshakeHandler(); @@ -90,6 +90,12 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { security_manager::SSLContext::HandshakeResult result) OVERRIDE; /** + * @brief Notification about handshake failure + * @return true on success notification handling or false otherwise + */ + bool OnHandshakeFailed() OVERRIDE; + + /** * @brief Notification that certificate update is required. */ void OnCertificateUpdateRequired() OVERRIDE; @@ -120,7 +126,7 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { SessionContext context_; ProtocolPacket::ProtocolVersion full_version_; const uint8_t protocol_version_; - std::shared_ptr<uint8_t> payload_; + std::shared_ptr<BsonObject> payload_; }; } // namespace protocol_handler diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h index 0efb81cdd7..58877ac611 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h @@ -42,8 +42,9 @@ #include "utils/prioritized_queue.h" #include "utils/message_queue.h" #include "utils/threads/message_loop_thread.h" -#include "utils/shared_ptr.h" + #include "utils/messagemeter.h" +#include "utils/custom_string.h" #include "protocol_handler/protocol_handler.h" #include "protocol_handler/protocol_packet.h" @@ -55,6 +56,7 @@ #include "transport_manager/common.h" #include "transport_manager/transport_manager.h" #include "transport_manager/transport_manager_listener_empty.h" +#include "transport_manager/transport_adapter/transport_adapter.h" #include "connection_handler/connection_handler.h" #include "application_manager/policies/policy_handler_observer.h" @@ -131,6 +133,30 @@ typedef threads::MessageLoopThread< utils::PrioritizedQueue<RawFordMessageFromMobile> > FromMobileQueue; typedef threads::MessageLoopThread< utils::PrioritizedQueue<RawFordMessageToMobile> > ToMobileQueue; + +// Type to allow easy mapping between a device type and transport +// characteristics +typedef enum { + TT_NONE = -1, + TT_USB = 0, + TT_BLUETOOTH = 1, + TT_WIFI = 2 +} TransportType; + +struct TransportDescription { + TransportDescription(const TransportType transport_type, + const bool ios_transport, + const bool android_transport) + : transport_type_(transport_type) + , ios_transport_(ios_transport) + , android_transport_(android_transport) {} + + TransportType transport_type_; + bool ios_transport_; + bool android_transport_; +}; + +typedef std::map<std::string, TransportDescription> TransportTypes; } // namespace impl /** @@ -231,10 +257,20 @@ class ProtocolHandlerImpl */ void SendEndSession(int32_t connection_id, uint8_t session_id); - void SendEndService(int32_t connection_id, + /** + * \brief Sends ending session to mobile application + * \param primary_connection_id Identifier of connection within which + * service exists + * \param connection_id Identifier of the actual transport for the service + * \param session_id ID of session to be ended + */ + void SendEndService(int32_t primary_connection_id, + int32_t connection_id, uint8_t session_id, uint8_t service_type); + void NotifyOnFailedHandshake() OVERRIDE; + // TODO(Ezamakhov): move Ack/Nack as interface for StartSessionHandler /** * \brief Sends acknowledgement of starting session to mobile application @@ -420,10 +456,19 @@ class ProtocolHandlerImpl const impl::ToMobileQueue& get_to_mobile_queue() const { return raw_ford_messages_to_mobile_; } + + void set_tcp_config(bool tcp_enabled, + std::string tcp_address, + std::string tcp_port) { + tcp_enabled_ = tcp_enabled; + tcp_ip_address_ = tcp_address; + tcp_port_ = tcp_port; + } #endif private: - void SendEndServicePrivate(int32_t connection_id, + void SendEndServicePrivate(int32_t primary_connection_id, + int32_t connection_id, uint8_t session_id, uint8_t service_type); @@ -434,6 +479,28 @@ class ProtocolHandlerImpl uint8_t session_id, uint32_t message_id); + /* + * Prepare and send TransportUpdateEvent message + */ + void SendTransportUpdateEvent(ConnectionID connection_id, uint8_t session_id); + + /* + * Prepare and send RegisterSecondaryTransportAck message + */ + RESULT_CODE SendRegisterSecondaryTransportAck( + ConnectionID connection_id, + ConnectionID primary_transport_connection_id, + uint8_t session_id); + + /* + * Prepare and send RegisterSecondaryTransportNAck message + */ + RESULT_CODE SendRegisterSecondaryTransportNAck( + ConnectionID connection_id, + ConnectionID primary_transport_connection_id, + uint8_t session_id, + BsonObject* reason = NULL); + /** * @brief Notifies about receiving message from TM. * @@ -472,13 +539,18 @@ class ProtocolHandlerImpl void OnConnectionClosed( const transport_manager::ConnectionUID connection_id) OVERRIDE; + void OnUnexpectedDisconnect( + const transport_manager::ConnectionUID connection_id, + const transport_manager::CommunicationError& error) OVERRIDE; + /** - * @brief OnPTUFinished the callback which signals PTU has finished + * @brief Notifies that configuration of a transport has been updated. * - * @param ptu_result the result from the PTU - true if successful, - * otherwise false. + * @param configs pairs of key and value that represent configuration. */ - void OnPTUFinished(const bool ptu_result) OVERRIDE; + void OnTransportConfigUpdated( + const transport_manager::transport_adapter::TransportConfig& configs) + OVERRIDE; /** * @brief Notifies subscribers about message @@ -581,6 +653,9 @@ class ProtocolHandlerImpl RESULT_CODE HandleControlMessageStartSession(const ProtocolFramePtr packet); + RESULT_CODE HandleControlMessageRegisterSecondaryTransport( + const ProtocolFramePtr packet); + RESULT_CODE HandleControlMessageHeartBeat(const ProtocolPacket& packet); void PopValideAndExpirateMultiframes(); @@ -609,6 +684,32 @@ class ProtocolHandlerImpl */ uint8_t SupportedSDLProtocolVersion() const; + const impl::TransportDescription GetTransportTypeFromConnectionType( + const std::string& device_type) const; + + const bool ParseSecondaryTransportConfiguration( + const ConnectionID connection_id, + std::vector<std::string>& secondaryTransports, + std::vector<int32_t>& audioServiceTransports, + std::vector<int32_t>& videoServiceTransports) const; + + void GenerateSecondaryTransportsForStartSessionAck( + const std::vector<std::string>& secondary_transport_types, + bool device_is_ios, + bool device_is_android, + std::vector<std::string>& secondaryTransports) const; + + void GenerateServiceTransportsForStartSessionAck( + bool secondary_enabled, + const std::vector<std::string>& service_transports, + const std::string& primary_connection_type, + const impl::TransportType primary_transport_type, + const std::vector<std::string>& secondary_transport_types, + std::vector<int32_t>& serviceTransports) const; + + const std::string TransportTypeFromTransport( + const utils::custom_string::CustomString& transport) const; + const ProtocolHandlerSettings& settings_; /** @@ -683,10 +784,6 @@ class ProtocolHandlerImpl #ifdef ENABLE_SECURITY security_manager::SecurityManager* security_manager_; - - bool is_ptu_triggered_; - std::list<std::shared_ptr<HandshakeHandler> > ptu_pending_handlers_; - sync_primitives::Lock ptu_handlers_lock_; #endif // ENABLE_SECURITY // Thread that pumps non-parsed messages coming from mobile side. @@ -699,6 +796,10 @@ class ProtocolHandlerImpl sync_primitives::Lock start_session_frame_map_lock_; StartSessionFrameMap start_session_frame_map_; + bool tcp_enabled_; + std::string tcp_port_; + std::string tcp_ip_address_; + #ifdef TELEMETRY_MONITOR PHTelemetryObserver* metric_observer_; #endif // TELEMETRY_MONITOR diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h index 1c427533e6..ff084beff8 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h @@ -252,6 +252,12 @@ class ProtocolPacket { const size_t messageSize); /** + * @brief Calculates FIRST_FRAME data for further handling of consecutive + * frames + */ + void HandleRawFirstFrameData(const uint8_t* message); + + /** * \brief Getter of protocol version. */ uint8_t protocol_version() const; @@ -326,6 +332,11 @@ class ProtocolPacket { ConnectionID connection_id() const; /** + * \brief Setter of Connection Identifier + */ + void set_connection_id(ConnectionID connection_id); + + /** * \brief Getter for data payload size */ uint32_t payload_size() const; @@ -364,7 +375,7 @@ class ProtocolPacket { * @brief Type definition for variable that hold shared pointer to protocolol * packet */ -typedef utils::SharedPtr<protocol_handler::ProtocolPacket> ProtocolFramePtr; +typedef std::shared_ptr<protocol_handler::ProtocolPacket> ProtocolFramePtr; typedef std::list<ProtocolFramePtr> ProtocolFramePtrList; template <typename _CharT> |