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

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

#include <doip_udp_channel_handler.h>

Collaboration diagram for doip_client::channel::udp_channel::DoipUdpChannelHandler:
Collaboration graph
[legend]

Public Types

using UdpMessagePtr = sockets::UdpSocketHandler::UdpMessagePtr
 Type alias for Tcp message pointer. More...
 

Public Member Functions

 DoipUdpChannelHandler (sockets::UdpSocketHandler &udp_socket_handler_broadcast, sockets::UdpSocketHandler &udp_socket_handler_unicast, DoipUdpChannel &channel)
 Constructs an instance of DoipUdpChannelHandler. More...
 
auto SendVehicleIdentificationRequest (uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
 Function to vehicle identification request to the connected network. More...
 
void HandleMessageUnicast (UdpMessagePtr udp_rx_message) noexcept
 Function to process the received unicast udp message. More...
 
void HandleMessageBroadcast (UdpMessagePtr udp_rx_message) noexcept
 Function to process the received broadcast udp message. 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...
 
void ProcessDoIPPayload (DoipMessage &doip_payload, DoipMessage::RxSocketType socket_type=DoipMessage::RxSocketType::kUnicast)
 Function to process the doip payload. More...
 

Static Private Member Functions

static auto ProcessDoIPPayloadLength (std::uint32_t payload_len, std::uint16_t payload_type) noexcept -> bool
 Function to verify payload length of various payload type. More...
 

Private Attributes

VehicleDiscoveryHandler vehicle_discovery_handler_
 Handler to process vehicle discovery messages. More...
 
VehicleIdentificationHandler vehicle_identification_handler_
 Handler to process vehicle identification req/res messages. More...
 
std::mutex channel_handler_lock
 Mutex to protect critical section. More...
 

Detailed Description

Class to handle udp received messages from lower layer.

Definition at line 28 of file doip_udp_channel_handler.h.

Member Typedef Documentation

◆ UdpMessagePtr

Type alias for Tcp message pointer.

Definition at line 33 of file doip_udp_channel_handler.h.

Constructor & Destructor Documentation

◆ DoipUdpChannelHandler()

doip_client::channel::udp_channel::DoipUdpChannelHandler::DoipUdpChannelHandler ( sockets::UdpSocketHandler udp_socket_handler_broadcast,
sockets::UdpSocketHandler udp_socket_handler_unicast,
DoipUdpChannel channel 
)

Constructs an instance of DoipUdpChannelHandler.

Parameters
[in]udp_socket_handler_broadcastThe reference to socket handler with broadcast mechanism
[in]udp_socket_handler_unicastThe reference to socket handler with unicast mechanism
[in]channelThe reference to tcp transport handler

Definition at line 30 of file doip_udp_channel_handler.cpp.

33  : vehicle_discovery_handler_{udp_socket_handler_broadcast, channel},
34  vehicle_identification_handler_{udp_socket_handler_unicast, channel} {}
VehicleDiscoveryHandler vehicle_discovery_handler_
Handler to process vehicle discovery messages.
VehicleIdentificationHandler vehicle_identification_handler_
Handler to process vehicle identification req/res messages.

Member Function Documentation

◆ HandleMessageBroadcast()

auto doip_client::channel::udp_channel::DoipUdpChannelHandler::HandleMessageBroadcast ( UdpMessagePtr  udp_rx_message)
noexcept

Function to process the received broadcast udp message.

Parameters
[in]udp_rx_messageThe message received

Definition at line 71 of file doip_udp_channel_handler.cpp.

71  {
72  uint8_t nack_code;
73  DoipMessage doip_rx_message{DoipMessage::MessageType::kUdp, udp_rx_message->GetHostIpAddress(),
74  udp_rx_message->GetHostPortNumber(),
75  core_type::Span<std::uint8_t>{udp_rx_message->GetRxBuffer()}};
76  // Process the Doip Generic header check
77  if (ProcessDoIPHeader(doip_rx_message, nack_code)) {
79  } else {
80  // send NACK or ignore
81  (void) nack_code;
82  }
83 }
auto ProcessDoIPHeader(DoipMessage &doip_rx_message, std::uint8_t &nack_code) noexcept -> bool
Function to process doip header in received response.
void ProcessVehicleAnnouncementResponse(DoipMessage &doip_payload) noexcept
Function to process received vehicle announcement response.

References doip_client::DoipMessage::kUdp.

Referenced by doip_client::channel::udp_channel::DoipUdpChannel::ProcessReceivedUdpBroadcast().

Here is the caller graph for this function:

◆ HandleMessageUnicast()

auto doip_client::channel::udp_channel::DoipUdpChannelHandler::HandleMessageUnicast ( UdpMessagePtr  udp_rx_message)
noexcept

Function to process the received unicast udp message.

Parameters
[in]udp_rx_messageThe message received

Definition at line 57 of file doip_udp_channel_handler.cpp.

57  {
58  std::uint8_t nack_code{};
59  DoipMessage doip_rx_message{DoipMessage::MessageType::kUdp, udp_rx_message->GetHostIpAddress(),
60  udp_rx_message->GetHostPortNumber(),
61  core_type::Span<std::uint8_t>{udp_rx_message->GetRxBuffer()}};
62  // Process the Doip Generic header check
63  if (ProcessDoIPHeader(doip_rx_message, nack_code)) {
64  ProcessDoIPPayload(doip_rx_message);
65  } else {
66  // send NACK or ignore
67  (void) nack_code;
68  }
69 }
void ProcessDoIPPayload(DoipMessage &doip_payload, DoipMessage::RxSocketType socket_type=DoipMessage::RxSocketType::kUnicast)
Function to process the doip payload.

References doip_client::DoipMessage::kUdp.

Referenced by doip_client::channel::udp_channel::DoipUdpChannel::ProcessReceivedUdpUnicast().

Here is the caller graph for this function:

◆ ProcessDoIPHeader()

auto doip_client::channel::udp_channel::DoipUdpChannelHandler::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 85 of file doip_udp_channel_handler.cpp.

85  {
86  bool ret_val{false};
87  /* Check the header synchronisation pattern */
88  if (((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion) &&
89  (doip_rx_message.GetInverseProtocolVersion() == static_cast<std::uint8_t>(~kDoip_ProtocolVersion))) ||
90  ((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion_Def) &&
91  (doip_rx_message.GetInverseProtocolVersion() == static_cast<std::uint8_t>(~kDoip_ProtocolVersion_Def)))) {
92  /* Check the supported payload type */
93  if (doip_rx_message.GetPayloadType() == kDoip_VehicleAnnouncement_ResType) {
94  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00017] */
95  if (doip_rx_message.GetPayloadLength() <= kDoip_Protocol_MaxPayload) {
96  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00018] */
97  if (doip_rx_message.GetPayloadLength() <= kUdpChannelLength) {
98  /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00019] */
99  if (ProcessDoIPPayloadLength(doip_rx_message.GetPayloadLength(), doip_rx_message.GetPayloadType())) {
100  ret_val = true;
101  } else {
102  // Send NACK code 0x04, close the socket
104  // socket closure ??
105  }
106  } else {
107  // Send NACK code 0x03, discard message
109  }
110  } else {
111  // Send NACK code 0x02, discard message
113  }
114  } else { // Send NACK code 0x01, discard message
116  }
117  } else { // Send NACK code 0x00, close the socket
119  // socket closure
120  }
121  return ret_val;
122 }
static 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::uint8_t kDoip_GenericHeader_IncorrectPattern
Generic DoIP Header NACK codes.
constexpr std::uint8_t kDoip_GenericHeader_OutOfMemory
constexpr std::uint8_t kDoip_GenericHeader_InvalidPayloadLen
constexpr std::uint8_t kDoip_GenericHeader_MessageTooLarge
constexpr std::uint8_t kDoip_GenericHeader_UnknownPayload
constexpr std::uint8_t kDoip_ProtocolVersion_Def
constexpr std::uint32_t kDoip_Protocol_MaxPayload
constexpr std::uint32_t kUdpChannelLength
constexpr std::uint16_t kDoip_VehicleAnnouncement_ResType
constexpr std::uint8_t kDoip_ProtocolVersion

References doip_client::channel::udp_channel::kDoip_GenericHeader_IncorrectPattern, doip_client::channel::udp_channel::kDoip_GenericHeader_InvalidPayloadLen, doip_client::channel::udp_channel::kDoip_GenericHeader_MessageTooLarge, doip_client::channel::udp_channel::kDoip_GenericHeader_OutOfMemory, doip_client::channel::udp_channel::kDoip_GenericHeader_UnknownPayload, doip_client::kDoip_Protocol_MaxPayload, doip_client::kDoip_ProtocolVersion, doip_client::kDoip_ProtocolVersion_Def, doip_client::kDoip_VehicleAnnouncement_ResType, and doip_client::kUdpChannelLength.

◆ ProcessDoIPPayload()

void doip_client::channel::udp_channel::DoipUdpChannelHandler::ProcessDoIPPayload ( DoipMessage doip_payload,
DoipMessage::RxSocketType  socket_type = DoipMessage::RxSocketType::kUnicast 
)
private

Function to process the doip payload.

Parameters
[in]doip_payloadThe reference to received payload

Definition at line 139 of file doip_udp_channel_handler.cpp.

139  {
140  std::lock_guard<std::mutex> const lck(channel_handler_lock);
141  switch (doip_payload.GetPayloadType()) {
144  break;
145  }
146  default:
147  /* do nothing */
148  break;
149  }
150 }
std::mutex channel_handler_lock
Mutex to protect critical section.
void ProcessVehicleIdentificationResponse(DoipMessage &doip_payload) noexcept
Function to process received vehicle identification response.

References channel_handler_lock, doip_client::DoipMessage::GetPayloadType(), doip_client::kDoip_VehicleAnnouncement_ResType, doip_client::channel::udp_channel::VehicleIdentificationHandler::ProcessVehicleIdentificationResponse(), and vehicle_identification_handler_.

Here is the call graph for this function:

◆ ProcessDoIPPayloadLength()

auto doip_client::channel::udp_channel::DoipUdpChannelHandler::ProcessDoIPPayloadLength ( std::uint32_t  payload_len,
std::uint16_t  payload_type 
) -> bool
staticprivatenoexcept

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 124 of file doip_udp_channel_handler.cpp.

125  {
126  bool ret_val{false};
127  switch (payload_type) {
129  if (payload_len <= kDoip_VehicleAnnouncement_ResMaxLen) ret_val = true;
130  break;
131  }
132  default:
133  // do nothing
134  break;
135  }
136  return ret_val;
137 }
constexpr std::uint32_t kDoip_VehicleAnnouncement_ResMaxLen

References doip_client::kDoip_VehicleAnnouncement_ResMaxLen, and doip_client::kDoip_VehicleAnnouncement_ResType.

◆ SendVehicleIdentificationRequest()

auto doip_client::channel::udp_channel::DoipUdpChannelHandler::SendVehicleIdentificationRequest ( uds_transport::UdsMessageConstPtr  vehicle_identification_request) -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
noexcept

Function to vehicle identification request to the connected network.

Parameters
[in]vehicle_identification_requestThe vehicle identification request
Returns
TransmissionResult The transmission result

Definition at line 36 of file doip_udp_channel_handler.cpp.

38  {
41  // Get the udp handler type from payload
42  std::uint8_t const handler_type{vehicle_identification_request->GetPayload()[BYTE_POS_ZERO]};
43  // deserialize and send to proper handler
44  switch (handler_type) {
45  case 0U:
46  // 0U -> Vehicle Identification Req
47  ret_val =
48  vehicle_identification_handler_.HandleVehicleIdentificationRequest(std::move(vehicle_identification_request));
49  break;
50  case 1U:
51  // 1U -> Power Mode Req
52  break;
53  }
54  return ret_val;
55 }
auto HandleVehicleIdentificationRequest(uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to handle sending of vehicle identification request.
constexpr uint8_t BYTE_POS_ZERO
Definition: common_header.h:31

References BYTE_POS_ZERO, and uds_transport::UdsTransportProtocolMgr::kTransmitFailed.

Referenced by doip_client::channel::udp_channel::DoipUdpChannel::Transmit().

Here is the caller graph for this function:

Member Data Documentation

◆ channel_handler_lock

std::mutex doip_client::channel::udp_channel::DoipUdpChannelHandler::channel_handler_lock
private

Mutex to protect critical section.

Definition at line 111 of file doip_udp_channel_handler.h.

Referenced by ProcessDoIPPayload().

◆ vehicle_discovery_handler_

VehicleDiscoveryHandler doip_client::channel::udp_channel::DoipUdpChannelHandler::vehicle_discovery_handler_
private

Handler to process vehicle discovery messages.

Definition at line 101 of file doip_udp_channel_handler.h.

◆ vehicle_identification_handler_

VehicleIdentificationHandler doip_client::channel::udp_channel::DoipUdpChannelHandler::vehicle_identification_handler_
private

Handler to process vehicle identification req/res messages.

Definition at line 106 of file doip_udp_channel_handler.h.

Referenced by ProcessDoIPPayload().


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