Disclosure of Invention
The invention aims to overcome the defects in the prior art, provides a CAN bus identifier, a communication method and a communication system, and solves the technical problems that the existing CAN bus has low safety when plaintext communication is adopted, and decoding errors are easily caused by asynchronous communication when a stream cipher algorithm is adopted, and normal communication is finally influenced.
In order to achieve the purpose, the invention is realized by adopting the following technical scheme:
in a first aspect, the present invention provides a CAN bus identifier, the identifier comprising:
a message index area: the message index is used for storing the current message;
counting area: the message index counting module is used for storing a message index counting result with the same type as the message index;
and (3) synchronizing the zone bit: used for representing the encryption condition of the current message data.
Further, the identifier includes a standard frame identifier and an extended frame identifier.
Further, the standard frame identifier includes a 7-bit packet index area, a 3-bit count area, and a 1-bit synchronization flag.
Further, the extended frame identifier includes a 20-bit packet index area, an 8-bit count area, and a 1-bit synchronization flag.
Further, when the synchronization flag bit is 0, the current message data is not encrypted; and when the synchronous flag bit is 1, the encryption of the current message data is represented.
In a second aspect, the present invention provides a packet sending method, including:
collecting a message to be sent;
generating the CAN-bus identifier of any of the first aspect;
judging whether a message to be sent needs to be encrypted according to a preset communication protocol:
if encryption is not needed, combining the message index area and the counting area into a new message index area, and adding the updated CAN bus identifier to a message to be sent for sending;
if the encryption is needed, executing a message encryption process to obtain a ciphertext; and updating the counting result of the message index stored in the counting area according to the message index in the ciphertext, and adding the updated CAN bus identifier to the ciphertext to send.
Further, the method comprises the steps of collecting the message to be sent, and then arranging the message to be sent into a required format according to the requirements of a preset communication protocol.
Furthermore, the counting area counts the counting result of the message index by adopting a circular counting mode, and when the counting result of the message index reaches the upper limit value of the counting area, the counting area starts counting from 0 again.
In a third aspect, the present invention provides a message receiving method, including:
acquiring a message to be received through a monitoring network;
judging whether the current message is an encrypted message according to the synchronous flag bit of the identifier in the message to be received:
if the message to be received is not an encrypted message, directly receiving the message;
if the message to be received is an encrypted message, obtaining a message index counting result of the current received message through a counting area of an identifier in the encrypted message: if the message index counting result is the same as the preset message index counting result, executing a message decryption process to receive and acquire a plaintext corresponding to the encrypted message; otherwise, continuing to acquire the message to be received through the monitoring network;
wherein the identifier is the CAN bus identifier of the first aspect.
In a fourth aspect, the present invention provides a CAN bus communication system comprising a plurality of ECU nodes connected to a CAN bus;
when the ECU node is used as a message sender, the message can be sent by adopting the message sending method of any one of the second aspect;
when the ECU node is used as a message receiver, the message receiving method of the third aspect may be used to receive a message.
Compared with the prior art, the invention has the following beneficial effects:
the invention provides a CAN bus identifier, a communication method and a communication system, which are suitable for CAN and CAN-FD bus communication, wherein the CAN and CAN-FD identifiers are divided into a message index area, a synchronous zone bit and a counting area 3 according to functions, when a message is sent, a sender carries out cycle counting on a specific message index in the counting area, and after the message is received by a receiver, the receiver compares the message with an expected counting value to judge whether the abnormity such as packet loss occurs or not, so that the aim of keeping data synchronous is fulfilled, and meanwhile, the bus load is not increased. A counting area is introduced into CAN and CAN-FD message identifiers, and a transmitting party and a receiving party perform data synchronization according to counting, so that the problem of data asynchronization in the communication process under the condition of adopting stream ciphers is solved.
Detailed Description
The invention is further described below with reference to the accompanying drawings. The following examples are only for illustrating the technical solutions of the present invention more clearly, and the protection scope of the present invention is not limited thereby.
Abbreviations and Key term definitions in the following examples
CAN- - -Controller Area Network
The CAN-FD- - -CAN with Flexible Data rate Data section with variable baud rate CAN be simply regarded as an upgrading version of the traditional CAN.
MCU- -Microcontroller Unit micro control Unit, also called singlechip
The ECU-Electronic Control Unit is composed of a Microprocessor (MCU), a memory (ROM, RAM), an input/output interface (I/O), an analog-to-digital converter (A/D), a shaping and driving large-scale integrated circuit and the like.
Stream cipher: stream Cipher (Stream Cipher), also known as sequential Cipher, is one type of symmetric Cipher algorithm. The sequence cipher has the characteristics of simple realization, convenient hardware implementation, high encryption and decryption processing speed, no or limited error propagation and the like, so the sequence cipher has advantages in practical application, particularly in special or confidential organizations, and typical application fields comprise wireless communication and bus communication.
The first embodiment is as follows:
the present embodiment provides a CAN bus identifier, where the identifier includes:
a message index area: the message index is used for storing the current message;
counting area: the message index counting module is used for storing the message index counting result with the same type as the message index;
and (3) synchronizing the zone bit: used for representing the encryption condition of the current message data.
As shown in fig. 1, a schematic diagram of a CAN data frame structure applicable to this embodiment, the method of the present invention is applicable to a CAN bus (11-bit standard frame and 29-bit extended frame identifier), and a CAN-FD, where a CAN data frame is composed of a frame start, an arbitration segment, a control segment, a data segment, a CRC segment, an ACK segment, and a frame end, and the identifier belongs to the arbitration segment;
as shown in fig. 2, the schematic diagram of the standard frame identifier allocation method of the present invention includes 11 bits (bit), which are bits 10-0, and 7 bits in total, which are bits 10-4, are packet index areas, and the value range is 0-127, so that the network supports a maximum of 128 packets; 3 bits of bit 3-bit 1 are a counting area, and the value range is 0-7, so that each cycle is 8 messages, and then starting from 0 again; bit0 is a synchronization flag bit, the synchronization flag bit is 0 to represent that the current message data is not encrypted, and the synchronization flag bit is 1 to represent that the current message data is encrypted;
fig. 3 shows a schematic diagram of the method for allocating an extended frame identifier according to the present invention, which has a total of 29 bits (bit), i.e., bit 28-bit 0, and bit 28-bit 9, i.e., 20 bits in total, i.e., a packet index area, with a value range of 0-220-1, so that the network supports a maximum of 220 (1048576) packets; 8 bits of bit 8-bit 1 are a counting area, and the value range is 0-255, so that each cycle is 256 messages, and then starting from 0 again; bit0 is a synchronization flag bit, the synchronization flag bit is 0 to represent that the current message data is not encrypted, and the synchronization flag bit is 1 to represent that the current message data is encrypted. And under the condition that the current message data is not encrypted, the synchronization flag bit is 0.
Example two:
the embodiment provides a message sending method, as shown in fig. 4, including:
the message to be sent is collected,
arranging the message to be sent into a required format according to the requirements of a preset communication protocol;
generating a CAN bus identifier as in embodiment one;
judging whether a message to be sent needs to be encrypted according to a preset communication protocol:
if encryption is not needed, combining the message index area and the counting area into a new message index area, and adding the updated CAN bus identifier to a message to be sent for sending; this is more flexible and can be applied to more complex networks. The method can realize the data sequence synchronization of the receiving and transmitting parties without increasing the number of messages and the bus load;
if the encryption is needed, executing a message encryption process to obtain a ciphertext; and updating the message index counting result stored in the counting area according to the message index in the ciphertext (counting the message index counting result by the counting area in a cycle counting mode, and counting the counting area from 0 again when the message index counting result reaches the upper limit value of the counting area), and adding the updated CAN bus identifier into the ciphertext to be transmitted.
Example three:
the embodiment provides a message receiving method, as shown in fig. 5, including:
acquiring a message to be received through a monitoring network;
judging whether the current message is an encrypted message according to the synchronous flag bit of the identifier in the message to be received:
if the message to be received is not an encrypted message, directly receiving the message;
if the message to be received is an encrypted message, obtaining a message index counting result of the current received message through a counting area of an identifier in the encrypted message: if the message index counting result is the same as the preset message index counting result, executing a message decryption process to receive and acquire a plaintext corresponding to the encrypted message; otherwise, continuing to acquire the message to be received through the monitoring network;
wherein, the identifier is a CAN bus identifier in the first embodiment.
The stream cipher has the characteristics that the encryption security is very high, and the cipher keys of the message data of each frame are different, so that the message receiver needs to generate the cipher key the same as that of the message sender to correctly decrypt the ciphertext data to obtain plaintext data. This requires that the sender and the receiver use the same key generation method, and the receiver and the sender can synchronize the data sequence, and once the data sequence is not synchronized, for example, the number of data packets is inconsistent, data packet is lost, and reception fails due to different starting times of the sender or the receiver, the system cannot work normally, so that a count is maintained for each functional data packet (a packet with the same index), and the data synchronization is indicated when the counts of the sender and the receiver are the same.
Example four:
the present embodiment provides a CAN bus communication system, as shown in fig. 6, including a plurality of ECU nodes connected to a CAN bus;
when the ECU node is used as a message sender, the message sending method of the second embodiment can be used to send a message;
when the ECU node is used as a message receiver, the message receiving method of the third embodiment can be used to receive a message.
In the CAN bus circuit, two terminal resistors for eliminating signal reflection are connected between a CAN _ H and a CAN _ L, the communication system comprises a plurality of ECU units which are connected in parallel between the CAH _ H and the CAN _ L, each ECU unit CAN be used for a plurality of message sending parties or a plurality of message receiving parties, and identifiers of the messages are distributed by adopting any identifier distribution method.
Each ECU unit may have a plurality of transmission messages and a plurality of reception messages, and the message indexes thereof are different, and these messages may be periodically transmitted or event type messages, and are counted respectively for different message indexes. The sending messages are all in a broadcast mode, when other ECU units receive the messages sent by a certain ECU unit, the value of a synchronous flag bit is judged, if the synchronous flag bit is 0, the data is not encrypted, a decryption program is not required to be executed, if the synchronous flag bit is 1, the value of a counting area is extracted, the data synchronization judgment is carried out, then a corresponding secret key is generated, and data decryption is carried out to obtain plaintext data for functional processing.
In summary, the present invention provides a CAN bus identifier allocation method, a communication system and a communication method using stream cipher, which are applicable to CAN and CAN-FD bus communication, the method divides the CAN and CAN-FD identifiers into a message index area, a synchronization flag bit and a counting area 3 according to functions, when sending a message, a sender performs a cycle counting for a specific message index in the counting area, after receiving the message, a receiver compares the message with an expected count value to determine whether an anomaly such as packet loss occurs, thereby achieving the purpose of keeping data synchronous without increasing bus load.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The above is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, several modifications and variations can be made without departing from the technical principle of the present invention, and these modifications and variations should also be regarded as the protection scope of the present invention.