15 #include "common/logger.h"
21 namespace tcp_channel {
181 msg <<
"unknown source address.";
184 msg <<
"all Socket active.";
187 msg <<
"SA different on already connected socket.";
190 msg <<
"SA active on different socket.";
193 msg <<
"missing authentication.";
196 msg <<
"rejected confirmation.";
199 msg <<
"unsupported routing activation type.";
202 msg <<
"required TLS socket.";
205 msg <<
"unknown reason.";
208 msg <<
" (0x" << std::hex << static_cast<int>(act_type.
act_type_) <<
")";
238 state_context_.
AddState(RoutingActivationState::kIdle, std::make_unique<kIdle>(RoutingActivationState::kIdle));
241 RoutingActivationState::kWaitForRoutingActivationRes,
242 std::make_unique<kWaitForRoutingActivationRes>(RoutingActivationState::kWaitForRoutingActivationRes));
245 RoutingActivationState::kRoutingActivationSuccessful,
246 std::make_unique<kRoutingActivationSuccessful>(RoutingActivationState::kRoutingActivationSuccessful));
249 RoutingActivationState::kRoutingActivationFailed,
250 std::make_unique<kRoutingActivationFailed>(RoutingActivationState::kRoutingActivationFailed));
323 if (handler_impl_->GetStateContext().GetActiveState().GetState() ==
324 RoutingActivationState::kWaitForRoutingActivationRes) {
327 switch (rout_act_type.act_type_) {
330 final_state = RoutingActivationState::kRoutingActivationSuccessful;
332 __FILE__, __LINE__, __func__, [&doip_payload](std::stringstream &msg) {
333 msg <<
"RoutingActivation successfully activated in remote server with logical Address"
334 <<
" (0x" << std::hex << doip_payload.GetServerAddress() <<
")";
340 __FILE__, __LINE__, __func__, [&doip_payload](std::stringstream &msg) {
341 msg <<
"RoutingActivation is activated, confirmation required in remote server with logical Address"
342 <<
" (0x" << std::hex << doip_payload.GetServerAddress() <<
")";
348 __FILE__, __LINE__, __func__,
349 [&rout_act_type](std::stringstream &msg) { msg <<
"Routing activation denied due to " << rout_act_type; });
352 handler_impl_->GetStateContext().TransitionTo(final_state);
353 handler_impl_->GetSyncTimer().CancelWait();
364 if (handler_impl_->GetStateContext().GetActiveState().GetState() == RoutingActivationState::kIdle) {
365 if (SendRoutingActivationRequest(std::move(routing_activation_request)) ==
368 handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kWaitForRoutingActivationRes);
369 handler_impl_->GetSyncTimer().WaitForTimeout(
372 handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle);
374 __FILE__, __LINE__,
"", [](std::stringstream &msg) {
375 msg <<
"RoutingActivation response timeout, no response received in: "
380 if (handler_impl_->GetStateContext().GetActiveState().GetState() ==
381 RoutingActivationState::kRoutingActivationSuccessful) {
385 __FILE__, __LINE__,
"",
386 [](std::stringstream &msg) { msg <<
"RoutingActivation successful with remote server"; });
388 handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle);
390 __FILE__, __LINE__,
"",
391 [](std::stringstream &msg) { msg <<
"RoutingActivation failed with remote server"; });
397 handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle);
399 __FILE__, __LINE__,
"",
400 [](std::stringstream &msg) { msg <<
"RoutingActivation Request send failed with remote server"; });
405 __FILE__, __LINE__,
"", [](std::stringstream &msg) { msg <<
"RoutingActivation channel not free"; });
411 return (
handler_impl_->GetStateContext().GetActiveState().GetState() ==
412 RoutingActivationState::kRoutingActivationSuccessful);
419 TcpMessagePtr doip_routing_act_req{std::make_unique<TcpMessage>()};
426 doip_routing_act_req->GetTxBuffer().emplace_back(
static_cast<std::uint8_t
>((message->GetSa() & 0xFF00) >> 8u));
427 doip_routing_act_req->GetTxBuffer().emplace_back(
static_cast<std::uint8_t
>(message->GetSa() & 0x00FF));
431 doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
432 doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
433 doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
434 doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
437 if (handler_impl_->GetSocketHandler().Transmit(std::move(doip_routing_act_req))) {
444 std::uint16_t payload_type, std::uint32_t payload_len) {
447 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_type & 0xFF00) >> 8));
448 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>(payload_type & 0x00FF));
449 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_len & 0xFF000000) >> 24));
450 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_len & 0x00FF0000) >> 16));
451 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>((payload_len & 0x0000FF00) >> 8));
452 doip_header_buffer.emplace_back(
static_cast<std::uint8_t
>(payload_len & 0x000000FF));
Immutable class to store received doip message.
Class implements routing activation handler.
RoutingActivationStateContext state_context_
Stores the routing activation states.
auto GetStateContext() noexcept -> RoutingActivationStateContext &
Function to get the Routing Activation State context.
sockets::TcpSocketHandler & tcp_socket_handler_
The reference to socket handler.
auto GetSyncTimer() noexcept -> SyncTimer &
Function to get the sync timer.
SyncTimer sync_timer_
Store the synchronous timer.
void Stop()
Function to stop the handler.
RoutingActivationHandlerImpl(sockets::TcpSocketHandler &tcp_socket_handler)
Constructs an instance of RoutingActivationHandlerImpl.
void Reset()
Function to reset the handler.
auto GetSocketHandler() noexcept -> sockets::TcpSocketHandler &
Function to get the socket handler.
void Start()
Function to start the handler.
void Stop()
Function to stop the handler.
sockets::TcpSocketHandler::TcpMessagePtr TcpMessagePtr
Type alias for Tcp message pointer.
static void CreateDoipGenericHeader(std::vector< std::uint8_t > &doip_header, std::uint16_t payload_type, std::uint32_t payload_len)
Function to create doip generic header.
void Reset()
Function to reset the handler.
void ProcessDoIPRoutingActivationResponse(DoipMessage &doip_payload) noexcept
Function to process received routing activation response.
auto SendRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to send routing activation request.
~RoutingActivationHandler()
Destruct an instance of RoutingActivationHandler.
RoutingActivationHandler(sockets::TcpSocketHandler &tcp_socket_handler)
Constructs an instance of RoutingActivationHandler.
std::unique_ptr< RoutingActivationHandlerImpl > handler_impl_
Stores the Handler implementation.
auto HandleRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult
Function to handle sending of routing activation request.
auto IsRoutingActivated() noexcept -> bool
Check if routing activation is active for this handler.
void Start()
Function to start the handler.
Class implements routing activation failure.
kRoutingActivationFailed(RoutingActivationState state)
Constructs an instance of kRoutingActivationFailed.
void Start() override
Function to start the current state.
void Stop() override
Function to stop the current state.
Class implements routing activation success.
kRoutingActivationSuccessful(RoutingActivationState state)
Constructs an instance of kRoutingActivationSuccessful.
void Start() override
Function to start the current state.
void Stop() override
Function to stop the current state.
Class implements idle state.
kIdle(RoutingActivationState state)
Constructs an instance of kIdle.
void Start() override
Function to start the current state.
void Stop() override
Function to stop the current state.
Class implements wait for routing activation response.
void Start() override
Function to start the current state.
kWaitForRoutingActivationRes(RoutingActivationState state)
Constructs an instance of kWaitForRoutingActivationRes.
void Stop() override
Function to stop the current state.
static auto GetDiagClientLogger() noexcept -> DoipClientLogger &
Class used to create a tcp socket for handling transmission and reception of tcp message from driver.
void TransitionTo(EnumState state)
void AddState(EnumState state, std::unique_ptr< State< EnumState >> state_ptr)
void CancelWait()
Function to cancel the synchronous wait.
auto IsTimerActive()
Function to query if timer is running.
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_AuthentnMissng
RoutingActivationState
Different routing activation state.
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_AllSocktActive
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_UnknownSA
Routing Activation response code values.
constexpr std::uint8_t kDoip_RoutingActivation_ReqActType_CentralSec
constexpr std::uint32_t kDoip_RoutingActivation_ReqMaxLen
constexpr std::uint8_t kDoip_RoutingActivation_ReqActType_Default
Routing Activation request activation types.
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_RoutingSuccessful
constexpr std::uint16_t kDoip_RoutingActivation_ResType
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_TLSRequired
constexpr std::uint32_t kDoip_RoutingActivation_ResMaxLen
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_ActiveSA
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_DifferentSA
constexpr std::uint8_t kDoip_RoutingActivation_ReqActType_WWHOBD
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_ConfirmtnRejectd
constexpr std::uint32_t kDoip_RoutingActivation_ReqMinLen
Routing Activation request lengths.
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_ConfirmtnRequired
constexpr std::uint32_t kDoip_RoutingActivation_ResMinLen
constexpr std::uint32_t kDoIPRoutingActivationTimeout
The timeout value for a DoIP Routing Activation request.
constexpr std::uint8_t kDoip_RoutingActivation_ResCode_UnsupportdActType
constexpr std::uint16_t kDoip_RoutingActivation_ReqType
Routing Activation response Type.
std::ostream & operator<<(std::ostream &msg, DiagAckType diag_ack_type)
Function to stream the diagnostic acknowledgement type.
void CreateDoipGenericHeader(std::vector< std::uint8_t > &doip_header_buffer, std::uint16_t payload_type, std::uint32_t payload_len)
Create the doip generic header.
constexpr std::uint8_t kDoipheadrSize
constexpr std::uint8_t kDoip_ProtocolVersion
std::unique_ptr< const UdsMessage > UdsMessageConstPtr
Type holding activation type.