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::MessagePtr
 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 30 of file doip_tcp_channel_handler.h.

Member Typedef Documentation

◆ TcpMessagePtr

Type alias for Tcp message pointer.

Definition at line 35 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.

68  : routing_activation_handler_{tcp_socket_handler},
69  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 99 of file doip_tcp_channel_handler.cpp.

99  {
100  std::uint8_t nack_code{};
101  DoipMessage doip_rx_message{DoipMessage::MessageType::kTcp, tcp_rx_message->GetHostIpAddress(),
102  tcp_rx_message->GetHostPortNumber(), tcp_rx_message->GetPayload()};
103  // Process the Doip Generic header check
104  if (ProcessDoIPHeader(doip_rx_message, nack_code)) {
105  ProcessDoIPPayload(doip_rx_message);
106  } else {
107  // send NACK or ignore
108  (void) nack_code;
109  }
110 }
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 112 of file doip_tcp_channel_handler.cpp.

112  {
114 }
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 116 of file doip_tcp_channel_handler.cpp.

117  {
118  bool ret_val = false;
119  /* Check the header synchronisation pattern */
120  if (((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion) &&
121  (doip_rx_message.GetInverseProtocolVersion() ==
122  static_cast<std::uint8_t>(~kDoip_ProtocolVersion))) ||
123  ((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion_Def) &&
124  (doip_rx_message.GetInverseProtocolVersion() ==
125  static_cast<std::uint8_t>(~kDoip_ProtocolVersion_Def)))) {
126  /* Check the supported payload type */
127  if ((doip_rx_message.GetPayloadType() == kDoip_RoutingActivation_ResType) ||
128  (doip_rx_message.GetPayloadType() == kDoipDiagMessagePosAck) ||
129  (doip_rx_message.GetPayloadType() == kDoipDiagMessageNegAck) ||
130  (doip_rx_message.GetPayloadType() == kDoipDiagMessage) ||
131  (doip_rx_message.GetPayloadType() == kDoip_AliveCheck_ReqType)) {
132  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00017] */
133  if (doip_rx_message.GetPayloadLength() <= kDoip_Protocol_MaxPayload) {
134  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00018] */
135  if (doip_rx_message.GetPayloadLength() <= kTcpChannelLength) {
136  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00019] */
137  if (ProcessDoIPPayloadLength(doip_rx_message.GetPayloadLength(),
138  doip_rx_message.GetPayloadType())) {
139  ret_val = true;
140  } else {
141  // Send NACK code 0x04, close the socket
143  // socket closure ??
144  }
145  } else {
146  // Send NACK code 0x03, discard message
148  }
149  } else {
150  // Send NACK code 0x02, discard message
152  }
153  } else { // Send NACK code 0x01, discard message
155  }
156  } else { // Send NACK code 0x00, close the socket
158  // socket closure
159  }
160  return ret_val;
161 }
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_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, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessage, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessageNegAck, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessagePosAck, 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 192 of file doip_tcp_channel_handler.cpp.

192  {
193  std::lock_guard<std::mutex> const lck(channel_handler_lock);
194  switch (doip_payload.GetPayloadType()) {
196  // Process RoutingActivation response
198  break;
199  case kDoipDiagMessage:
200  // Process Diagnostic Message Response
202  break;
205  // Process positive or negative diag ack message
207  break;
208  default:
209  /* do nothing */
210  break;
211  }
212 }
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_RoutingActivation_ResType, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessage, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessageNegAck, and doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessagePosAck.

◆ 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 163 of file doip_tcp_channel_handler.cpp.

164  {
165  bool ret_val{false};
166  switch (payload_type) {
168  if (payload_length <= kDoipRoutingActivationResMaxLen) ret_val = true;
169  break;
170  }
172  case kDoipDiagMessageNegAck: {
173  if (payload_length >= kDoipDiagMessageAckResMinLen) ret_val = true;
174  break;
175  }
176  case kDoipDiagMessage: {
177  // Atleast 1 byte of data must be present
178  if (payload_length >= (kDoipDiagMessageReqResMinLen + 1u)) ret_val = true;
179  break;
180  }
182  if (payload_length <= kDoipRoutingActivationResMaxLen) ret_val = true;
183  break;
184  }
185  default:
186  // do nothing
187  break;
188  }
189  return ret_val;
190 }
constexpr std::uint8_t kDoipDiagMessageReqResMinLen
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_RoutingActivation_ResType, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessage, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessageAckResMinLen, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessageNegAck, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessagePosAck, doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipDiagMessageReqResMinLen, and doip_client::channel::tcp_channel::anonymous_namespace{doip_tcp_channel_handler.cpp}::kDoipRoutingActivationResMaxLen.

◆ 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 81 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 93 of file doip_tcp_channel_handler.cpp.

95  {
96  return diagnostic_message_handler_.HandleDiagnosticRequest(std::move(diagnostic_request));
97 }
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 86 of file doip_tcp_channel_handler.cpp.

88  {
90  std::move(routing_activation_request));
91 }
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 76 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 137 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 132 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 127 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: