Module programming via CAN

Everything regarding communication-protocols like CAN, OBD, LIN, JTAG, BDM, I2C, SPI, ...
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Module programming via CAN

Post by Go4IT »

Hi there! I know there is a standard way for programming modules in cars using the CAN protocol. Let's find this out and maybe get a way to hack into cars modules (microcontrollers)!

The magic word here is UDS (UNIFIED DIAGNOSTIC SERVICES), defined in ISO 14229. OBD-II is a limited subset of it, used for emission relevant diagnostic services. UDS instead provides all the services needed for also flashing firmwares. Just to say, the ISO is not public and one needs to pay for it, but i'm shure there are other:ways to get our hands on it! :twisted:
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Module programming via CAN

Post by Go4IT »

Well, in fact it took me one minute and a single Google query ("filetype:pdf iso 14229") to find the full ISO here http://read.pudn.com/downloads191/doc/8 ... (2006).pdf ;)
i don't go and rrad all the 300 pages yet, but it will shure be a good reference.
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Module programming via CAN

Post by Go4IT »

Learning by examples is always a good jumpstart. So here i attach a CAN-log made with CANhacker (one of my favorite tools) from a Ford AFS module programming (Firmware update) session. I've done it with UCDS on the desk. So only the module and the programmer is involved in the communication. This was my setup:
hardwareaufbau_update.jpg
This is was the module looks like:
afs-modul_7s71-13k031-af.jpg
Inside, we find good old pals, like the "NEC 70F3231" (position IC1):
afs-modul_7s71-13k01-af_component-side.png
afs-modul_7s71-13k01-af_solder-side.png
I bet the 8pin unpopulated header on the left of IC8 is an programming interface for the module. Most vendors use such headers in the development phase or for initial programming.

But, let's inspect the CAN-log as we want to learn about programming by CAN, not by serial:

The relevant CAN-IDs inside the logfile are 0x734 (this is OBD-ID of the AFS module) and 0x73C (this is the dynamic OBD-ID of the programmer). On the beginning of the file you can see how the UCDS is scanning the bus for modules until it gets an positive response from the AFS module.

Lets start with the first valid communication. I've therefore picked the start from the log with an arbitrary length:

Code: Select all

...
07,861 734      8 02 10 02 00 00 00 00 00 
07,877 73C      8 06 50 02 00 19 01 F4 00 
08,890 734      8 02 27 01 00 00 00 00 00 
08,891 73C      8 05 67 01 03 22 43 00 00 
08,893 734      8 05 27 02 E9 AF D1 00 00 
08,895 73C      8 02 67 02 00 00 00 00 00 
08,957 734      8 10 0B 34 00 44 FF FF D9 
08,958 73C      8 30 00 00 00 00 00 00 00 
08,960 734      8 21 50 00 00 01 86 00 00 
08,961 73C      8 04 74 20 00 82 00 00 00 
08,969 734      8 10 82 36 01 85 0D 81 3F 
08,970 73C      8 30 00 00 00 00 00 00 00 
08,975 734      8 21 01 00 45 3F 00 00 41 
...
Because CAN is message oriented, the first thing the UCDS (we call it "programmer") do is to send this to the bus:

Code: Select all

07,861 734      8 02 10 02 00 00 00 00 00 
The first column is the timecode, we can ignore, next comes the message-ID of the CAN frame. The AFS module will receive this, because it knows itself by this ID. The message is set to a length of 8 bytes, indicated by the 3rd column value. As we see, the remaining is payload (data) for the CAN protocol and so we are switching to OSI layer 7 here.

The payload seems to be padded to 8 bytes using zeros, which is very common. The first payload byte is protocol specific and denotes the number of bytes, the following message will use. This can be more than one CAN frame can carry, but more to this later. Here we have 2 bytes and so in fact this is the message we should care is:

Code: Select all

10 02
From the docs we know that UDS uses a "request / response" method for communicating. So this first one must be a request from the programmer to the module. The docs telling us, that each request contains the "Service Identifier" (SID) first and, depending on it's type, parameters for it. Now we are looking for the SID "10", what it means and what params it takes. The service 0x10 is known as "DiagnosticSessionControl" and is used to open a special session with the module. The next byte is the only parameter for this and tells with subfunction to use. The docs tell us that 0x02 is for "programmingSession".

In the next line we find the response of this request (for simplicity i only quote the real payload):

Code: Select all

50 02 00 19 01 F4
As per the docs, all request messages must have set Bit 6 of SID to 0 and all positive response messages must have set Bit 6 to 1. So with request SID of 0x10 (binary is written 0b0001 0000), the positive response SID is 0x50 (0b0101 0000). The SID code of 0x7F is reserved to denote a negative response.

In the next Byte the called function is repeated: 0x02. As of the standard, the response usually end here, but there are some extra bytes. Currently i have no clue what they mean. The standard allows sending n'th params. Maybe this is Ford specific or any kind of entrophy.

UCDS told us that there must be 3 files downloaded to the module:
ucds_afs_firmware_downloaded.png
It was pretty easy to get those files using the download-URL http://www.ucdsys.ru/calibration/
After unziping and extracting the binary part of it, i had the 3 files UCDS would upload, and also the order they should appear in the log. A simple textsearch for the first and last 4 bytes shows me where the data gets send to the module:
"7S7T-14C087-AB" starts at logline 131 and ends at 1019
"7S7T-14C084-AK" starts at logline 1042 and ends at 19878
"7S7T-14C399-AC" starts at logline 19893 and ends at 20262
A closer inspection of the sending process shows the beauty of transport segmentation protocol of CAN, defined in ISO 15765-2. As you know a standard CAN frame can contain up to 8 Bytes of payload. To send larger ammounts of data, multiple, consecutive frames are necessary, spreading the data over the frames (called "segmentation"). The ISO defines an easy way to do this with less overhead.

All the CAN messages inbetween are needed for setup the module for updating. Removing the data transmittion itself dramatically reduces the communication log.
You do not have the required permissions to view the files attached to this post.
Last edited by Go4IT on 11 Feb 2019, 07:31, edited 9 times in total.
Gwe89
Pro
Posts: 332
Joined: 09 Feb 2019, 21:21

Re: Module programming via CAN

Post by Gwe89 »

Hey where can I get a can hacker?
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Module programming via CAN

Post by Go4IT »

CANhacker itself is a Windows software. It needs an CAN interface (known as "CAN-to-USB" type) which uses the LAWICEL protocol on the USB-side. There are several units using this, from simple Arduino+MCP2515 up to real good ones using an STM32+TJA1050.
I should make a list of tools and hardware i know and place it here...
User avatar
Stevebe
Pro
Posts: 258
Joined: 08 Feb 2019, 12:28

Re: Module programming via CAN

Post by Stevebe »

Last edited by Stevebe on 15 Feb 2019, 16:50, edited 1 time in total.
Digimod
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Module programming via CAN

Post by Go4IT »

Yeah, know these ones. There are many out there. Only watch out it was compatible for LAWICEl protocol, so it can be used with the opensource tools also.
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Module programming via CAN

Post by Go4IT »

User avatar
Stevebe
Pro
Posts: 258
Joined: 08 Feb 2019, 12:28

Re: Module programming via CAN

Post by Stevebe »

Go4IT wrote: 14 Feb 2019, 16:01 Actually my favorite is this one https://www.elektronik-keller.de/index. ... 2-can-v1-2
Shame it’s not available
Digimod
geier99

Re: Module programming via CAN

Post by geier99 »

I have updated the page, so you can order the previous version if you want. (only shipped to europe)
Both version has the same function, there is only one less LED mounted and the bug-fix (1 missing connection) is being solved by hand as you will see in the picture.
Or you can also make your own version and download the hex-file and flash it with the ST-Link Utility.
Post Reply