back to index

CAN bus
      Hardware level
            packet format
                  bit stuffing
            remote frame:
            CAN FD - Flexible Data
      Protocol level - SAE J1939
            J1939 specs
            PGN - Parameter Group Numbers
            SPN - Suspect Parameter Number
            payload
                  multipacket
            other common protocols
                  common CAN-based protocols
      Field definitions
            DBC files
            EDS files
      OBD-II connector
            CAN
            "K-line"
      Computer interfaces
            SocketCAN on raspi
            ELM327 on raspi
                  dongle interface hacking thoughts
                  dongle LEDs
                  dongle bluetooth parameters
                  connect
                  attach
                  access
                  some dump during putzing with ELM
            AT commands
      Tools

CAN bus


Hardware level

CAN bus (Controller Area Network)

bit transmitting: 1 ("dominant", "L" on input) pulls line from idle state, 0 ("recessive", "H", or inactive) leaves it idle/undriven

packet format

arbitration field

data field CRC field end of frame

bit stuffing

except CRC-delimiter, ACK slot and and end-of-frame sequence, bit stuffing is used to prevent too long sequences without an edge

remote frame:

CAN FD - Flexible Data


Protocol level - SAE J1939

SAE J1939, http://read.pudn.com/downloads344/ebook/1503048/A%20Comprehensible%20Guide%20to%20J1939.pdf

J1939 specs

PGN - Parameter Group Numbers

ID format with PGN:

hex format:

SPN - Suspect Parameter Number

payload

multipacket

other common protocols

common CAN-based protocols


Field definitions

DBC files

https://medium.com/@energee/what-are-dbc-files-469a3bf9b04b

EDS files

for CANopen


OBD-II connector

vehicle (female):

                           __--^^.
                          /       |
                       9  | O| |O |  1
     SAE J1850 bus -  10  | O| |O |  2   + SAE J1850 bus
                      11  | O| |O |  3
                      12  | O| |O |  4   GND chassis
                      13  | O| |O |  5   GND signal
    ISO 15765-4 CANL  14  | O| |O |  6   CANH - ISO 15765-4
              L-line  15  | O| |O |  7   K-line
                +12V  16  | O| |O |  8
                          \       |
                           ^^--__'

Pins 1,9,3,11,12,13,8 are used at manufacturer discretion:

CAN

ISO 15765-4 - CANH/CANL

"K-line"

ISO 9141-2, ISO 14230 - K-line/L-line


Computer interfaces

SocketCAN on raspi

 sudo /sbin/ip link set can0 up type can bitrate 500000
...or, add to /etc/network/interfacesd/can0:
 auto can0
 iface can0 inet manual
     pre-up /sbin/ip link set can0 type can bitrate 500000 triple-sampling on restart-ms 100
     up /sbin/ifconfig can0 up
     down /sbin/ifconfig can0 down

ELM327 on raspi

ELM327 is a microcontroller interface for the OBD-II port on not-so-ancient cars. On one side it communicates via several protocols. On the other there is a serial port.

Multiple ELM327 device flavors exist:

Raspberry Pi 3B, internal bluetooth used

caution: Raspi 3B's bluetooth module uses the same serial port as the serial console. Make sure the console is disabled. if there are problems with bluetooth, make sure the login terminal is not interfering; typically agetty is doing that.

Make sure there is no console=ttyAMA0,115200 in /boot/cmdline.txt

To /boot/config.txt put:

 enable_uart=1
 dtoverlay=pi3-miniuart-bt

Reboot and things should work like a charm.

dongle interface hacking thoughts

The ELM327 chip that gives the dongle its name has a plain UART output. The conversion to USB or Bluetooth is handled by another chip.

It should be possible to tap the circuitboard and mix and match interfaces as needed, without having to source a different dongle for each interface.

dongle LEDs

dongle bluetooth parameters

info via bluetoothctl:

[bluetooth]# info 00:00:00:33:33:33
Device 00:00:00:33:33:33 (public)
        Name: OBDII
        Alias: OBDII
        Class: 0x00001f00
        Paired: no
        Trusted: no
        Blocked: no
        Connected: no
        LegacyPairing: no
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: L2CAP                     (00000100-0000-1000-8000-00805f9b34fb)
        UUID: SDP                       (00000001-0000-1000-8000-00805f9b34fb)
        UUID: Serial Port               (00001101-0000-1000-8000-00805f9b34fb)
        UUID: RFCOMM                    (00000003-0000-1000-8000-00805f9b34fb)
        RSSI: -70

connect

bt-device -c 00:00:00:33:33:33
Connecting to: 00:00:00:33:33:33
Device: OBDII (00:00:00:33:33:33)
Enter passkey: 1234
Done

attach

rfcomm bind /dev/rfcomm0 00:00:00:33:33:33
...voila, rfcomm0 appears in /dev

rfcomm0 is an ordinary serial communication device, through which the dongle operates.

access

run picocom

 picocom /dev/rfcomm0
ATI
ELM327 v2.1

some dump during putzing with ELM

what the dongle apparently sent to the bus (protocol #7)

  can0  0C08A7F0   [8]  00 7D 00 00 1A 27 93 31
  can0  0C09A7F0   [8]  6E 37 38 38 1A 27 00 00
  can0  0C09A7F0   [8]  6E 37 38 38 1A 27 00 00
  can0  0C0BA7F0   [8]  78 2D F4 01 00 00 00 00
  can0  0C19F0A7   [8]  00 7D FF FF FF FF C0 2C
  can0  0C0BA7F0   [8]  78 2D F4 01 00 00 00 00
  can0  0C19F0A7   [8]  00 7D FF FF FF FF C0 2C
  can0  0C08A7F0   [8]  00 7D 00 00 1A 27 93 32
  can0  0C08A7F0   [8]  00 7D 00 00 1A 27 93 32
  can0  0C09A7F0   [8]  6E 37 38 38 1A 27 00 00
  can0  0C09A7F0   [8]  6E 37 38 38 1A 27 00 00

AT commands

mode 03 request:

03
UNABLE TO CONNECT
on CAN:
can0  18DB33F1  [8] 01 03 00 00 00 00 00 00
can0  18DB33F1  [8] 01 03 00 00 00 00 00 00

mode 01 PID 01 request

01 01
UNABLE TO CONNECT
can0  18DB33F1  [8] 01 01 00 00 00 00 00 00 can0  18DB33F1  [8] 01 03 00 00 00 00 00 00 can0  18DB33F1  [8] 02 01 01 00 00 00 00 00 can0  18DB33F1  [8] 02 01 01 00 00 00 00 00


Tools

https://pypi.org/project/cantools/

https://github.com/ebroecker/canmatrix

https://github.com/linklayer/pyvit - Python Vehicle Interface Toolkit

https://github.com/brendan-w/python-OBD

https://github.com/Ircama/ELM327-emulator

https://github.com/zombieCraig/UDSim

https://github.com/cedricp/ddt4all

https://github.com/educampos28/OBD2_HACK

https://github.com/EricSmekens/node-bluetooth-obd

https://github.com/jgamblin/CarHackingTools

Wireshark


If you have any comments or questions about the topic, please let me know here:
Your name:
Your email:
Spambait
Leave this empty!
Only spambots enter stuff here.
Feedback: