What is can-utils and how we can use it to simply get packets from our Engine Control Unit (ECU).
If you are using Linux and Debian based operating system you can install can-utils by this easy command :
sudo apt install can-utils
If you don’t have can utils in your apt packet manager, you can install it from github by simply typing this command into your terminal :
The compatibility drivers for your Linux operating system :
These are the device lists where Linux drivers supports for can bus fuzzing with can-utils.
Controller Area Bus controllers like the SJA1000 these controllers are usually built into ISA,PCMIA, PCI structure.
When we insert the famous EMS PCMICA device to our computer these are the timeline of what happens :
- ems_pcmciam module loads into the kernel
- ems_pcmciam module loads other modules cja1000 and can_dev (for setting bit rates for the Controller Area Network controllers)
The Linux Kernel
The Linux kernel’s modular structure also applies to Controller Are Network hardware drivers that connect CAN controllers via bus hardware, such as the kvaser_pci, peak_pci, and so on. When you plug in a compatible device, these modules should automatically be loaded, and you should see them when you enter the lsmod command into the terminal. USB drivers, like usb8dev, usually implement a proprietary USB communication protocol and, therefore, do not load a CAN controller driver.
For example, when you connect in a PEAK-System PCAN-USB adapter, the can_dev module loads and the peak_usb module finalizes its initialization. Using the display message command dmesg, you should see output similar to this:
ocsaly@ubuntu:dmesg [ 3602.633057] CAN device driver interface [ 3602.638635] peak_usb 3-2:1.0: PEAK-System PCAN-USB adapter hwrev 32 serial FFFFFFFF (1 channel) [ 3602.639554] peak_usb 3-2:1.0 can0: attached to PCAN-USB channel 1 (device 255) [ 3602.639664] usbcore: registered new interface driver peak_usb
If you want to verify the interface loaded properly or not, you can check this with ifconfig can0 command :
ocsaly@ubuntu: ifconfig can0 can0 Link encap:UNSPEC HWaddr 01-01-01-01-01-01-01-01-01-01-01-01-01-01-01-01 UP RUNNING NOARP MTU:16 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Actually you can set the CAN Bus speed ! The important component you should set is the BITRATE ! Bitrate is the speed of the CAN BUS, A standard value for High Speed Can [HS-CAN] is 512,000 Bytes/Per Second (512 KBps) , Bitrate for Low Speed CANBus is 125Kbps or 250Kbps.
Lets set the CAN Bus Speed !
ocsaly@ubuntu : sudo ip link set can0 type can bitrate 512000 ocsaly@ubuntu :sudo ip link set up can0
After you setup the can0 device, you should also be able to use the tools
from can-utils on this interface to perform such operation . Linux uses netlink layer to communicate between the kernel and user-space tools. You can access netlink with the ip link command. To see all the netlink options, enter this command below :
ocsaly@ubuntu:ip link set can0 type can help
If you begin to see something went wrong or some strange behavior, such as a error of packet captures and packet reading errors, the interface may have stopped. If you’re working with an external device, just unplug or reset. If the device is internal, run the quoted commands to reset or reboot it:
ocsaly@ubuntu: sudo ip link set canX type can restart-ms 100 ocsaly@ubuntu: sudo ip link set canX type can restart