CAN is a network protocol designed to communicate among various ECUs within a vehicle. In the CAN protocol, each data packet is assigned a unique message ID to form a message-based communication structure [
7,
8]. This allows all ECUs within the network to control communication independently without a central control unit. Additionally, it provides error detection and recovery features capable of identifying and managing various types of errors.
Additionally, as shown in
Figure 1, the ECU within a vehicle adopts a multi-master architecture, where collisions can occur if multiple ECUs attempt to communicate simultaneously. To prevent this, an arbitration process is performed to determine the communication priority. The arbitration process operates on a bit-level comparison. When a Dominant Bit (Logic 0) and a Recessive Bit (Logic 1) are transmitted simultaneously, the Dominant Bit takes precedence. Through this method, the message IDs are compared, and ultimately, the message with the lowest ID is assigned the highest priority.
2.1.1. Frame
A CAN Frame is the basic unit of data transmission, containing the transmitted data, along with its associated control information. CAN Frames are categorized into four types: Data Frame, Remote Frame, Overload Frame, and Error Frame, each serving the following roles, respectively:
Remote Frame: A frame used to request data associated with a specific message ID. It does not transmit any data but only includes the ID for the request.
Overload Frame: A frame transmitted when the network is in an overloaded state, temporarily halting communication and requesting additional time for data processing.
Error Frame: A frame transmitted when an error is detected, notifying the network of its occurrence.
Data Frame: A frame used for actual data transmission, sending information from the transmitting ECU to receiving ECU.
In this study, only Error and Data Frames were considered. The CAN Data Frame is shown in
Figure 2, and the role of each field is as follows.
The Start of Frame (SOF) is a single bit that signals the start of a frame, enabling the ECU connected to the network to recognize and synchronize the beginning of the frame accordingly.
The Arbitration Field contains the unique ID of the message and is responsible for determining its priority. It is composed of the Identifier (ID) and Remote Transmission Request (RTR). The ID is 11 bits long in the CAN Standard and 29 bits long in the Extended format. In this study, the Standard format is used, with the ID set to 11 bits. The RTR is a single bit used to differentiate between Data Frames and Remote Frames. A Dominant Bit is used to indicate a Data Frame.
The control Field contains information regarding the size and type of the Data Field of the current frame. It is composed of 6 bits, including Reserved Bits and the Data Length Code (DLC). The Reserved Bits are the two bits allocated to the future functionality. In this study, DLC was limited to values between 0 and 8.
The data Field contains the actual transmitted data. The size of the data is determined by the DLC, and the data are transmitted in the order of Most Significant Bit.
The CRC Field performs error detection in the frames. It is composed of a Cyclic Redundancy Check (CRC) Sequence and a Delimiter Bit. The CRC Sequence contained a 15-bit CRC value calculated using the SOF, Arbitration Field, Control Field, Data Field, and the CRC-15 Polynomial. The Delimiter Bit is a single Recessive Bit used to mark the end of a CRC Field. The transmitted CRC value in the CRC Sequence is compared with the CRC value calculated using the receiving ECU. If the values do not match, the receiving ECU can request the transmitting ECU to resend the frame.
The ACK Field indicates to the transmitting ECU whether data were successfully received by the receiving ECU. It comprises an ACK Slot and the Delimiter Bit. If the data were successfully received, a Dominant Bit was transmitted in the ACK Slot.
The End of Frame (EOF) is the field that signals the End of Frame. It comprises seven consecutive Recessive Bits.
The Interframe Space (IFS) represents the gap between frames. It consists of three consecutive Recessive Bits indicating the minimum interval between frames. This prevents collisions between consecutive frames and enhances communication reliability.
2.1.2. Error Handling
CAN communication detects and manages errors in stages such as error detection, error counter management, and error state transitions. It can identify five types of errors: Bit, Stuff, CRC, Form, and ACK Error.
A Bit Error occurs when the bit transmitted by the sending ECU is different from the actual bit received by the CAN BUS. However, exceptions include cases where a Stuff Bit or the ACK Slot is transmitted as a Dominant Bit, in which no Bit Error is triggered [
7,
8]. In addition, Bit Errors do not occur when a transmitting ECU in the Passive Error Flag state detects a Dominant Bit.
A Stuff Error occurs when the sixth consecutive identical bit appears in an encoded Frame Field, violating the bit-stuffing rule. As shown in
Figure 3, bit-stuffing is used to maintain synchronization and assist in error detection during data transmission. This method inserts the opposite bit when five identical consecutive bits are detected.
A CRC Error occurs when the CRC value calculated by the receiving ECU is different from the CRC value transmitted by the sending ECU.
Form Error occurs when a fixed-format Bit Field, such as a Delimiter Bit or EOF contains a bit that does not conform to the required format. However, a Form Error does not occur if the receiving ECU detects a Dominant Bit in the last bit of the EOF or monitors a Dominant Bit in the last bit of the Error Delimiter.
An ACK Error occurs when, after sending a message, the transmitting ECU detects a Recessive Bit in the ACK Slot instead of a Dominant Bit from the receiving ECU connected to a CAN BUS.
The ECUs connected to the CAN BUS exist in one of three error states, as shown in
Figure 4. These states are managed through a Transmission Error Counter (TEC), which counts errors occurring during transmission, and the Receive Error Counter (REC), which counts errors occurring during reception. When an error is detected, the TEC typically increases by eight and the REC increases by one [
5,
6]. Conversely, when communication occurs without errors, both the TEC and REC decrease by 1.
Error Active is the default state of an ECU that allows normal participation in CAN BUS communication. When either the TEC or REC reaches 128, the state transitions to Error Passive. If the counters fall below 128, the state reverts to Error Active. Additionally, when an error occurs, the ECU transmits an Active Error Frame, as shown in
Figure 5.
Passive error is a state in which the ECU transmits a Passive Error Frame when an error occurs, as shown in
Figure 6. After transmitting the Passive Error Frame, any subsequent transmission requires the ECU to wait before retrying. If TEC exceeds 255, the ECU transitions to a bus-off state.
A bus-off is a state in which the ECU can no longer participate in communication and cannot influence the bus. This occurs when an ECU is isolated from the network. If 11 consecutive Recessive Bits are detected 128 times on the bus, the TEC and REC are reset to zero, and the ECU transitions back to the error-active state.
2.1.3. Attack Type
Network attacks within vehicles involve hacking an ECU to inject malicious messages into the CAN BUS, thereby disrupting the normal functionality of the vehicle [
9]. This study addresses Denial of Service (DoS), Fuzzy, and Spoofing attacks.
DoS Attack is, as shown in
Figure 7, where a hacked ECU leverages the CAN communication arbitration process to send a large number of low-priority messages, disrupting normal communication. By transmitting these messages repeatedly at short intervals, an attack can saturate the CAN BUS, thereby preventing the transmission of legitimate messages.
A Fuzzy Attack, as depicted in
Figure 8, involves transmitting messages with randomly generated IDs and data to the CAN BUS. This disrupts the transmission of legitimate messages and causes devices to malfunction. From the perspective of the hacker, the attack is relatively simple to execute, as it only requires sending messages with random IDs and data. However, these messages are uncommon in normal communication scenarios, which makes them easier to detect from the perspective of an IDS.
A Spoofing Attack, as shown in
Figure 9, occurs when a compromised ECU monitors messages transmitted on the CAN BUS for a period of time and then impersonates a legitimate ECU to send false data to the bus. By mimicking a specific ECU, the attack causes other ECUs to operate based on incorrect information. In some cases, the attack replicates the exact data of legitimate messages, making a distinction between normal and malicious messages difficult for the receiving ECU. This makes the attack particularly dangerous from the perspective of the driver.