Diag-Client-Lib
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
doip_client::channel::tcp_channel::DoipTcpChannelHandler Class Referencefinal

Class to handle tcp received messages from lower layer. More...

#include <doip_tcp_channel_handler.h>

Collaboration diagram for doip_client::channel::tcp_channel::DoipTcpChannelHandler:
Collaboration graph
[legend]

Public Types

using TcpMessagePtr = sockets::TcpSocketHandler::TcpMessagePtr
 Type alias for Tcp message pointer. More...
 

Public Member Functions

 DoipTcpChannelHandler (sockets::TcpSocketHandler &tcp_socket_handler, DoipTcpChannel &channel)
 Constructs an instance of DoipTcpChannelHandler. More...
 
void Start ()
 Function to start the handler. More...
 
void Stop ()
 Function to stop the handler. More...
 
void Reset ()
 Function to reset the handler. More...
 
auto SendRoutingActivationRequest (uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult
 Function to send routing activation request. More...
 
auto SendDiagnosticRequest (uds_transport::UdsMessageConstPtr diagnostic_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
 Function to send diagnostic request. More...
 
void HandleMessage (TcpMessagePtr tcp_rx_message) noexcept
 Function to process the received message. More...
 
auto IsRoutingActivated () noexcept -> bool
 Check if routing activation is active for this handler. More...
 

Private Member Functions

auto ProcessDoIPHeader (DoipMessage &doip_rx_message, std::uint8_t &nack_code) noexcept -> bool
 Function to process doip header in received response. More...
 
auto ProcessDoIPPayloadLength (std::uint32_t payload_len, std::uint16_t payload_type) noexcept -> bool
 Function to verify payload length of various payload type. More...
 
void ProcessDoIPPayload (DoipMessage &doip_payload) noexcept
 Function to process the doip payload. More...
 

Private Attributes

RoutingActivationHandler routing_activation_handler_
 Handler to process routing activation req/ resp. More...
 
DiagnosticMessageHandler diagnostic_message_handler_
 Handler to process diagnostic message req/ resp. More...
 
std::mutex channel_handler_lock
 Mutex to protect critical section. More...
 

Detailed Description

Class to handle tcp received messages from lower layer.

Definition at line 28 of file doip_tcp_channel_handler.h.

Member Typedef Documentation

◆ TcpMessagePtr

Type alias for Tcp message pointer.

Definition at line 33 of file doip_tcp_channel_handler.h.

Constructor & Destructor Documentation

◆ DoipTcpChannelHandler()

doip_client::channel::tcp_channel::DoipTcpChannelHandler::DoipTcpChannelHandler ( sockets::TcpSocketHandler tcp_socket_handler,
DoipTcpChannel channel 
)

Constructs an instance of DoipTcpChannelHandler.

Parameters
[in]tcp_socket_handlerThe reference to socket handler
[in]channelThe reference to tcp transport handler

Definition at line 66 of file doip_tcp_channel_handler.cpp.

67  : routing_activation_handler_{tcp_socket_handler},
68  diagnostic_message_handler_{tcp_socket_handler, channel} {}
RoutingActivationHandler routing_activation_handler_
Handler to process routing activation req/ resp.
DiagnosticMessageHandler diagnostic_message_handler_
Handler to process diagnostic message req/ resp.

Member Function Documentation

◆ HandleMessage()

auto doip_client::channel::tcp_channel::DoipTcpChannelHandler::HandleMessage ( TcpMessagePtr  tcp_rx_message)
noexcept

Function to process the received message.

Parameters
[in]tcp_rx_messageThe message received

Definition at line 96 of file doip_tcp_channel_handler.cpp.

96  {
97  std::uint8_t nack_code{};
98  DoipMessage doip_rx_message{DoipMessage::MessageType::kTcp, tcp_rx_message->GetHostIpAddress(),
99  tcp_rx_message->GetHostPortNumber(),
100  core_type::Span<std::uint8_t>{tcp_rx_message->GetRxBuffer()}};
101  // Process the Doip Generic header check
102  if (ProcessDoIPHeader(doip_rx_message, nack_code)) {
103  ProcessDoIPPayload(doip_rx_message);
104  } else {
105  // send NACK or ignore
106  (void) nack_code;
107  }
108 }
void ProcessDoIPPayload(DoipMessage &doip_payload) noexcept
Function to process the doip payload.
auto ProcessDoIPHeader(DoipMessage &doip_rx_message, std::uint8_t &nack_code) noexcept -> bool
Function to process doip header in received response.

References doip_client::DoipMessage::kTcp.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::ProcessReceivedTcpMessage().

Here is the caller graph for this function:

◆ IsRoutingActivated()

auto doip_client::channel::tcp_channel::DoipTcpChannelHandler::IsRoutingActivated ( ) -> bool
noexcept

Check if routing activation is active for this handler.

Returns
True if activated, otherwise False

Definition at line 110 of file doip_tcp_channel_handler.cpp.

110  {
112 }
auto IsRoutingActivated() noexcept -> bool
Check if routing activation is active for this handler.

References doip_client::channel::tcp_channel::RoutingActivationHandler::IsRoutingActivated(), and routing_activation_handler_.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::DisconnectFromHost(), and doip_client::channel::tcp_channel::DoipTcpChannel::Transmit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessDoIPHeader()

auto doip_client::channel::tcp_channel::DoipTcpChannelHandler::ProcessDoIPHeader ( DoipMessage doip_rx_message,
std::uint8_t &  nack_code 
) -> bool
privatenoexcept

Function to process doip header in received response.

Parameters
[in]doip_rx_messageThe received doip rx message
[in]nack_codeThe negative ack code

Definition at line 114 of file doip_tcp_channel_handler.cpp.

114  {
115  bool ret_val = false;
116  /* Check the header synchronisation pattern */
117  if (((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion) &&
118  (doip_rx_message.GetInverseProtocolVersion() == static_cast<std::uint8_t>(~kDoip_ProtocolVersion))) ||
119  ((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion_Def) &&
120  (doip_rx_message.GetInverseProtocolVersion() == static_cast<std::uint8_t>(~kDoip_ProtocolVersion_Def)))) {
121  /* Check the supported payload type */
122  if ((doip_rx_message.GetPayloadType() == kDoip_RoutingActivation_ResType) ||
123  (doip_rx_message.GetPayloadType() == kDoip_DiagMessagePosAck_Type) ||
124  (doip_rx_message.GetPayloadType() == kDoip_DiagMessageNegAck_Type) ||
125  (doip_rx_message.GetPayloadType() == kDoip_DiagMessage_Type) ||
126  (doip_rx_message.GetPayloadType() == kDoip_AliveCheck_ReqType)) {
127  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00017] */
128  if (doip_rx_message.GetPayloadLength() <= kDoip_Protocol_MaxPayload) {
129  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00018] */
130  if (doip_rx_message.GetPayloadLength() <= kTcpChannelLength) {
131  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00019] */
132  if (ProcessDoIPPayloadLength(doip_rx_message.GetPayloadLength(), doip_rx_message.GetPayloadType())) {
133  ret_val = true;
134  } else {
135  // Send NACK code 0x04, close the socket
137  // socket closure ??
138  }
139  } else {
140  // Send NACK code 0x03, discard message
142  }
143  } else {
144  // Send NACK code 0x02, discard message
146  }
147  } else { // Send NACK code 0x01, discard message
149  }
150  } else { // Send NACK code 0x00, close the socket
152  // socket closure
153  }
154  return ret_val;
155 }
auto ProcessDoIPPayloadLength(std::uint32_t payload_len, std::uint16_t payload_type) noexcept -> bool
Function to verify payload length of various payload type.
constexpr std::uint16_t kDoip_RoutingActivation_ResType
Routing Activation response Type.
constexpr std::uint8_t kDoip_GenericHeader_IncorrectPattern
Generic DoIP Header NACK codes.
constexpr std::uint8_t kDoip_ProtocolVersion_Def
constexpr std::uint32_t kDoip_Protocol_MaxPayload
constexpr std::uint8_t kDoip_ProtocolVersion
constexpr std::uint32_t kTcpChannelLength

References doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_AliveCheck_ReqType, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessage_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessageNegAck_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessagePosAck_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_GenericHeader_IncorrectPattern, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_GenericHeader_InvalidPayloadLen, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_GenericHeader_MessageTooLarge, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_GenericHeader_OutOfMemory, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_GenericHeader_UnknownPayload, doip_client::kDoip_Protocol_MaxPayload, doip_client::kDoip_ProtocolVersion, doip_client::kDoip_ProtocolVersion_Def, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_RoutingActivation_ResType, and doip_client::kTcpChannelLength.

◆ ProcessDoIPPayload()

void doip_client::channel::tcp_channel::DoipTcpChannelHandler::ProcessDoIPPayload ( DoipMessage doip_payload)
privatenoexcept

Function to process the doip payload.

Parameters
[in]doip_payloadThe reference to received payload

Definition at line 186 of file doip_tcp_channel_handler.cpp.

186  {
187  std::lock_guard<std::mutex> const lck(channel_handler_lock);
188  switch (doip_payload.GetPayloadType()) {
190  // Process RoutingActivation response
192  break;
194  // Process Diagnostic Message Response
196  break;
199  // Process positive or negative diag ack message
201  break;
202  default:
203  /* do nothing */
204  break;
205  }
206 }
void ProcessDoIPDiagnosticAckMessageResponse(DoipMessage &doip_payload) noexcept
Function to process received diagnostic acknowledgement from server.
void ProcessDoIPDiagnosticMessageResponse(DoipMessage &doip_payload) noexcept
Function to process received diagnostic positive/negative response from server.
std::mutex channel_handler_lock
Mutex to protect critical section.
void ProcessDoIPRoutingActivationResponse(DoipMessage &doip_payload) noexcept
Function to process received routing activation response.

References doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessage_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessageNegAck_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessagePosAck_Type, and doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_RoutingActivation_ResType.

◆ ProcessDoIPPayloadLength()

auto doip_client::channel::tcp_channel::DoipTcpChannelHandler::ProcessDoIPPayloadLength ( std::uint32_t  payload_len,
std::uint16_t  payload_type 
) -> bool
privatenoexcept

Function to verify payload length of various payload type.

Parameters
[in]payload_lenThe length of payload received
[in]payload_typeThe type of payload

Definition at line 157 of file doip_tcp_channel_handler.cpp.

158  {
159  bool ret_val{false};
160  switch (payload_type) {
162  if (payload_length <= kDoip_RoutingActivation_ResMaxLen) ret_val = true;
163  break;
164  }
167  if (payload_length >= kDoip_DiagMessageAck_ResMinLen) ret_val = true;
168  break;
169  }
170  case kDoip_DiagMessage_Type: {
171  // Atleast 1 byte of data must be present
172  if (payload_length >= (kDoip_DiagMessage_ReqResMinLen + 1u)) ret_val = true;
173  break;
174  }
176  if (payload_length <= kDoip_RoutingActivation_ResMaxLen) ret_val = true;
177  break;
178  }
179  default:
180  // do nothing
181  break;
182  }
183  return ret_val;
184 }
constexpr std::uint8_t kDoip_DiagMessage_ReqResMinLen
Diagnostic Message request/response lengths.

References doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_AliveCheck_ReqType, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessage_ReqResMinLen, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessage_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessageAck_ResMinLen, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessageNegAck_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_DiagMessagePosAck_Type, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_RoutingActivation_ResMaxLen, and doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoip_RoutingActivation_ResType.

◆ Reset()

void doip_client::channel::tcp_channel::DoipTcpChannelHandler::Reset ( )

Function to reset the handler.

This will reset all the internal handler back to default state

Definition at line 80 of file doip_tcp_channel_handler.cpp.

References diagnostic_message_handler_, doip_client::channel::tcp_channel::DiagnosticMessageHandler::Reset(), doip_client::channel::tcp_channel::RoutingActivationHandler::Reset(), and routing_activation_handler_.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::DisconnectFromHost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendDiagnosticRequest()

auto doip_client::channel::tcp_channel::DoipTcpChannelHandler::SendDiagnosticRequest ( uds_transport::UdsMessageConstPtr  diagnostic_request) -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
noexcept

Function to send diagnostic request.

Parameters
[in]diagnostic_requestThe diagnostic request
Returns
TransmissionResult The transmission result

Definition at line 91 of file doip_tcp_channel_handler.cpp.

92  {
93  return diagnostic_message_handler_.HandleDiagnosticRequest(std::move(diagnostic_request));
94 }
auto HandleDiagnosticRequest(uds_transport::UdsMessageConstPtr diagnostic_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to handle sending of diagnostic request.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::Transmit().

Here is the caller graph for this function:

◆ SendRoutingActivationRequest()

auto doip_client::channel::tcp_channel::DoipTcpChannelHandler::SendRoutingActivationRequest ( uds_transport::UdsMessageConstPtr  routing_activation_request) -> uds_transport::UdsTransportProtocolMgr::ConnectionResult
noexcept

Function to send routing activation request.

Parameters
[in]routing_activation_requestThe routing activation request
Returns
ConnectionResult The connection result

Definition at line 85 of file doip_tcp_channel_handler.cpp.

87  {
88  return routing_activation_handler_.HandleRoutingActivationRequest(std::move(routing_activation_request));
89 }
auto HandleRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult
Function to handle sending of routing activation request.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::ConnectToHost().

Here is the caller graph for this function:

◆ Start()

void doip_client::channel::tcp_channel::DoipTcpChannelHandler::Start ( )

◆ Stop()

void doip_client::channel::tcp_channel::DoipTcpChannelHandler::Stop ( )

Function to stop the handler.

This will reset all the internal handler back to default state

Definition at line 75 of file doip_tcp_channel_handler.cpp.

References diagnostic_message_handler_, routing_activation_handler_, doip_client::channel::tcp_channel::DiagnosticMessageHandler::Stop(), and doip_client::channel::tcp_channel::RoutingActivationHandler::Stop().

Referenced by doip_client::channel::tcp_channel::DoipTcpChannel::Stop().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ channel_handler_lock

std::mutex doip_client::channel::tcp_channel::DoipTcpChannelHandler::channel_handler_lock
private

Mutex to protect critical section.

Definition at line 133 of file doip_tcp_channel_handler.h.

◆ diagnostic_message_handler_

DiagnosticMessageHandler doip_client::channel::tcp_channel::DoipTcpChannelHandler::diagnostic_message_handler_
private

Handler to process diagnostic message req/ resp.

Definition at line 128 of file doip_tcp_channel_handler.h.

Referenced by Reset(), Start(), and Stop().

◆ routing_activation_handler_

RoutingActivationHandler doip_client::channel::tcp_channel::DoipTcpChannelHandler::routing_activation_handler_
private

Handler to process routing activation req/ resp.

Definition at line 123 of file doip_tcp_channel_handler.h.

Referenced by IsRoutingActivated(), Reset(), Start(), and Stop().


The documentation for this class was generated from the following files: