AUTOMOTIVE UDS SERVICES
Tags: autosar, vectorbootlader, uds, daignostics
Published: 2023-04-10 09:29:02


Hi folks, I'm Sree Harika employee of **LUXOFT India**. Here I would like to provide a brief knowledge about  UDS Services.

**Why UDS in automotive?**
If car is not working fine and facing some issue. For finding the issue UDS will helps us where exactly problem was present, and he will try to fix the issue. Within short period of time.
If UDS protocol is not available, then it is very difficult to find the issue where exactly issue was present, and it is time taking process to fix the issue.

**What is UDS?**
UDS: Unified Diagnostic Services.
**UDS Protocol Request Frame Format:**
•	Whenever the client wants to request anything from the data then the tester will send this request the frame to get the response from the server on the CAN data field. This frame had consisted of 3 fields:
•	Service ID.
•	Sub-Function ID (optional: not exist for some diag. services).
•	Data bytes.
In the message format 
•	0th byte indicates the message length. 
•	1st byte indicates SID information.
•	2nd byte indicates the Sub Function.

**Why Diagnostics?**
In a complex machine and if vehicle contains more ECU and it is very difficult to find the defect from which source we are facing failure, for this type of problems diagnostics helps the tester to detect the failure from which source exact defect is available and root cause as well. Diagnostics will monitor several sensors, located throughout the engine, fuel etc.,
With the help of Diagnostics in two ways to outside world can understand whether really issue was present or not.
1.	With help of warning lamp and this warning lamp will alert the driver there will be a problem in our car.
2.	Second one with the help of DTC code service person can understand what exactly issue was present and from which source. For each DTC there will be a pre-defined definition based on that service person, developer and tester can understand the problem. The DTC will be stored in EEPROM.

**What is Diagnostic?**
Based on the word we can understand it will help us to identify the cause of a problem or a situation. Whenever the ECU finds a problem, it stores that problem as a Diagnostic Trouble Code (DTC) it the EEPROM.
With the help of Diagnostic tool, we can read the DTC’s from EEPROM to find the root cause of a failure.

**What is DTC?**
DTC is Diagnostic Trouble code: with the help of DTC’s, we can understand what exactly failure happen in our system and this DTC code will store in EEPROM. 

**What is DID?**
DID: Data identifier is mainly useful to read and write the data in between client and server.
Client means Tester/End user.
Server means ECU.

**What is unit Services?**
Normally the functional unit or services will help us to control the diagnostic functionalities in the ECU.
The communication will happen in between client and server.
The services are divided in to 6 different types based on the functionalities. 
For each services their will, be a Service ID, Sub Function.
The services will work based on the request and response method will follow.
1.	Diagnostic and communication management.
2.	Data Transmission.
3.	Stored Data Transmission.
4.	Input and Output Control.
5.	Remote Activation of unit.
Upload Diagnostic and communication management.
Under this section 10 more service are available.
1.	Diagnostic Session Control.
2.	ECU Reset.
3.	Communication Control.
4.	Accessing timing parameter
5.	Secured Data Transmission.
6.	Control DTC Setting.
7.	Response on Event.
8.	Link Control.
9.	Security Access.
10.	Tester Present.
For example, I will explain the request and frame format of Request and response:
**UDS Protocol Response Frame Format:**
•	Whenever a diagnostic engineer or tester will request any service to a vehicle, there is a possibility of two types of response from the vehicle or a particular ECU as per physical or functional request type.

**Positive Response Frame Format:**
•	Whenever the tester will request to the server if it is correct and the server has been executed the request successfully, then it will send the response message concerning this request by adding 0x40 to the respective service ID for reference. Positive response 1st byte should be Request Service ID + 0x40.

**Negative Response Frame Format:**
•	If the client did not request in a proper frame format or the server is not able to execute the request due to the internal problem, then it will send a negative response to the client.
•	Negative response 1st byte should be 0x7F.
•	Negative response 2nd byte should be Service ID.
•	Negative response 3rd byte should be Response Code.
**Diagnostic Session Control (0x10 02) service:**
•	This diagnostic Session enables all diagnostic services required to support the
     memory programming of a ECU.
•	Programming Session used to upload software.
•	Extended Diagnostic Session used to unlock additional diagnostic functions, such as the adjustment of sensors.
•	 Safety system diagnostic session used to test all safety-critical diagnostic functions, such as airbag tests.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itrsmlafyve52rqukzk3.png)

•	Request Download (0x34) service:
•	The request Download service is used by the client (Tester ECU) to initiate a data transfer from the client(Tester ECU) to the server.
     (download).
•	After The Server (Server ECU) has received the request Download request message the server shall take all necessary actions to receive data before it Sends a positive Response Message. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12s0dtq5olk5jq8nsjz2.png)
**Transfer Data (0x36) service:**
•	The Transfer Data service is used by the client (Tester ECU) to transfer data either from the client (Tester ECU) to the server (Server ECU) or from the server to the client (Tester ECU).
•	The data transfer direction is defined after Request Download or Request Upload service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqr7cff67hcfp2h9kf4m.png)
 
Request Transfer Exit (0x37) service:
•	The request File Transfer service is used by the client to initiate a file data transfer from either the client to the
     server (server ECU) or from the server to the client (Tester Ecu). 
•	Additionally, this service has capabilities to retrieve information about the file system.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6dh0cl2ahtqvgnx2i72.png)
**Routine Control (31 Hex) Service:**
If client requested a routine with a routine identifier, then server will stop the normal operation mode and routine will enable with the normal operation mode with the specified routine identifier.
The main use of Routine control service to test the critical functionality like air bag system whether it is working or not for that routine identifier will be configured, client can test the functionality of air bag with the routine control service mentioned with the identifier.
Sub functions
1 - Start a routine.
2 – Stop a Routine.
3 – Request the Routine result.
Steps to follow to test the routine.
1.	Start a routine
2.	Stop a routine
3.	Request result for the routine identifier.
The above steps should follow in sequence
For the above service negative response will update with NRC 12, 13, 22, 24, 31 33 and 72
12 – Sub function not supported.
13 – Invalid message length.
22 – Condition does not correct.
24 – Request sequence error.
31- Request out of Range.
33 – Security Access Denied.
72 – General Programming Failure
service ID 31 in negative response case 03 7F 31 12 00 00 00 00 Indicates Sub function not supported.
       service ID 31 in negative response case 03 7F 31 13 00 00 00 00 Invalid message length.

       service ID 31 in negative response case 03 7F 31 22 00 00 00 00 Indicates Condition does not correct.

       service ID 31 in negative response case 03 7F 31 24 00 00 00 00 Indicates Request sequence error.

       service ID 31 in negative response case 03 7F 31 31 00 00 00 00 Indicates Request out of Range.

       service ID 31 in negative response case 03 7F 31 33 00 00 00 00 Indicates Security Access Denied.

       service ID 31 in negative response case 03 7F 31 72 00 00 00 00 Indicates General Programming Failure.