Data interaction method based on SPI (Serial Peripheral Interface)
By introducing the INT control pin and data link layer protocol into the SPI interface, efficient data interaction between the digital identity terminal and the encryption chip is achieved, which solves the problem of transmission rate and compatibility, and satisfies the encrypted transmission of large amounts of data for digital identity applications. need.
Patent Information
- Application Number
- CN202311338849.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-16
- Publication Date
- 2024-10-18
AI Technical Summary
The existing SPI interface for communication between digital identity terminals and encryption chips has a low transmission rate and cannot meet the large data transmission requirements of digital identity applications. Furthermore, different devices cannot unify the link layer protocols, leading to compatibility issues.
A data interaction method based on the SPI interface is designed. Protocol synchronization and data block transmission are realized through the INT control pin. The data link layer protocol is used for synchronization and verification to ensure the correct interaction and error correction of the data block. It is suitable for intelligent applications. Encryption card or encryption chip.
It realizes the unification of the SPI interface on the link layer protocol, improves the data transmission rate between the digital identity terminal and the encryption chip, solves the compatibility problem, and meets the large-volume encryption transmission requirements of digital identity applications.
Smart Images

Figure CN118802952A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data transmission, and in particular to a data interaction method, a main control chip, an encryption chip and a system based on an SPI interface. Background Art
[0002] At present, most of the solutions for digital identity terminals and encryption chips on the market use the ISO7816 interface, which has a low transmission rate. The digital identity application based on 5G Super SIM transmits a large amount of certificate information data. In order to ensure the efficiency of business execution, it is particularly urgent to use a high-speed interface to complete the data interaction between the terminal and the encryption chip. The traditional SPI interface only proposes the protocol of the physical transmission layer, and is mostly used in traditional industrial fields. It does not propose a hardware solution for communicating with smart encryption cards or encryption chips. The data link layer protocol is not explained, resulting in different SPI interface devices being unable to unify on the link layer protocol. The SPI interface solution in some industrial fields proposes a data link layer protocol, but the signal transmitted by its link layer protocol is relatively simple and cannot be applied to the requirements for APDU instruction transmission in the communication field of smart encryption cards or encryption chips. Summary of the invention
[0003] The main purpose of the present invention is to provide a data interaction method, a main control chip, an encryption chip and a system based on an SPI interface, aiming to solve the technical problem of how to achieve the unification of the SPI interface on the link layer protocol while meeting the transmission requirements of large amounts of data for digital identity applications.
[0004] To achieve the above object, the present invention provides a data interaction method based on an SPI interface, which is applied to a main control chip, wherein the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin. The data interaction method based on the SPI interface includes: When the INT control pin is at a preset level, a protocol synchronization data block is sent to the encryption chip, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; When receiving the protocol response information fed back by the encryption chip, setting the current state to a waiting-to-send state; Sending the content sending data block to the encryption chip according to the ready-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information; When the content response information received within the first time threshold is successful reception information, the content reception block number and the content transmission block number are adjusted according to the link information of the content transmission data block, and the data interaction is completed according to the adjustment result.
[0005] Optionally, when the INT control pin is at a preset level, after sending a protocol synchronization data block to the encryption chip so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block, the method further includes: If the protocol response information is not received within the second time threshold, the step of sending the protocol synchronization data block to the encryption chip is performed again, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; Get the number of repeated executions; When the number of repeated executions exceeds a preset number threshold, a protocol synchronization error is reported and the encryption chip is reset.
[0006] Optionally, after sending the content sending data block to the encryption chip according to the ready-to-send state so that the encryption chip receives the content sending data block and feeds back content response information, the method further includes: When the content response information received within the first time threshold is transmission termination information, terminating the transmission of the content transmission data block according to the transmission termination information, and sending a transmission termination response to the encryption chip; When the content response information received within the first time threshold is length modification information, determining a domain target length according to the length modification information, modifying the information domain length according to the domain target length, and sending a length modification response to the encryption chip; When the content response information received within the first time threshold is reception response information, the response block number is determined according to the reception response information, and a block number comparison is performed according to the response block number and the content sending block number. When the block number comparison results are consistent, the content sending data block is resent.
[0007] Optionally, after sending the content sending data block to the encryption chip according to the ready-to-send state so that the encryption chip receives the content sending data block and feeds back content response information, the method further includes: When the content response information received within the first time threshold is timeout waiting information, performing information verification on the timeout waiting information; When the information verification result is that the timeout waiting information is the preset waiting information, resetting the waiting time according to the timeout waiting information and the first time threshold, and sending a timeout waiting response to the encryption chip; When the information verification result is that the timeout waiting information is not the preset waiting information, a receiving response data block is sent to the encryption chip according to the timeout waiting information, so that the encryption chip re-feeds back the timeout waiting information according to the receiving response data block.
[0008] Optionally, adjusting the content receiving block number and the content sending block number according to the link information of the content sending data block includes: Determine whether the content sending data block has a link according to the link information of the content sending data block; When the content sending data block has a link, the content receiving block number is flipped and adjusted to keep the content sending block number; When there is no link in the content sending data block, both the content receiving block number and the content sending block number are flipped and adjusted.
[0009] Optionally, setting the current state to a waiting-to-send state includes: According to the protocol response information, the block numbers of the content receiving data block and the content sending data block are set to preset values to obtain a data block reset result; According to the data block reset result, it is determined that the current state is a waiting-to-send state.
[0010] In addition, to achieve the above purpose, the present invention also provides a data interaction method based on an SPI interface, which is applied to an encryption chip. The data interaction method based on the SPI interface includes: When receiving the power-on instruction sent by the main control chip, the level of the INT control pin of the main control chip is adjusted to make the INT control pin of the main control chip a preset level, and a protocol synchronization data block is fed back, the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin; Synchronize the data link layer protocol according to the protocol synchronization data block and generate protocol response information; Sending the protocol response information to the main control chip, so that the main control chip sets the current state to a waiting-to-send state according to the protocol response information, and sends the content data block to the encryption chip according to the waiting-to-send state; Generate content response information according to the content sending data block, and send the content response information to the main control chip, so that when the content response information received by the main control chip within a first time threshold is successfully received information, adjust the content receiving block number and the content sending block number according to the link information of the content sending data block, and complete data interaction according to the adjustment result.
[0011] In addition, to achieve the above object, the present invention further provides a main control chip, the main control chip comprising: A sending module, used for sending a protocol synchronization data block to the encryption chip when the INT control pin is at a preset level, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; A processing module, configured to set the current state to a waiting-to-send state upon receiving the protocol response information fed back by the encryption chip; The sending module is further used to send the content sending data block to the encryption chip according to the waiting-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information; The adjustment module is further used to adjust the content receiving block number and the content sending block number according to the link information of the content sending data block when the content response information received within the first time threshold is successful reception information, and complete data interaction according to the adjustment result.
[0012] In addition, to achieve the above object, the present invention also provides an encryption chip, the encryption chip comprising: The adjustment module is used to adjust the level of the INT control pin of the main control chip when receiving the power-on instruction sent by the main control chip, so that the INT control pin of the main control chip is at a preset level, and feedback the protocol synchronization data block, the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin; A synchronization module, used to synchronize the data link layer protocol according to the protocol synchronization data block and generate protocol response information; A sending module, used for sending the protocol response information to the main control chip, so that the main control chip sets the current state to a waiting-to-send state according to the protocol response information, and sends the content and data block to the encryption chip according to the waiting-to-send state; A generating module is used to generate content response information according to the content sending data block, and send the content response information to the main control chip, so that when the content response information received by the main control chip within the first time threshold is successfully received information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, and the data interaction is completed according to the adjustment result.
[0013] In addition, to achieve the above-mentioned purpose, the present invention further proposes a data interaction system based on an SPI interface, wherein the data interaction system based on the SPI interface comprises the main control chip as described above and the encryption chip as described above.
[0014] The present invention is applied to a main control chip, the main control chip is provided with an SPI interface and a USB interface, the SPI interface comprises an INT control pin, and the data interaction method based on the SPI interface comprises: when the INT control pin is at a preset level, sending a protocol synchronization data block to an encryption chip, so that the encryption chip performs synchronization of a data link layer protocol according to the protocol synchronization data block; when receiving protocol response information fed back by the encryption chip, setting the current state to a waiting-to-send state; sending a content sending data block to the encryption chip according to the waiting-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information; when the content response information received within a first time threshold is successfully received information, adjusting a content receiving block number and a content sending block number according to link information of the content sending data block, and completing data interaction according to the adjustment result. Through the above method, the main control chip sends the protocol synchronization data block to the encryption chip, the encryption chip synchronizes the data link layer protocol, and sends the content sending data block to the encryption chip in the waiting state. When the content response information received within the first time threshold is the successful reception information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, so as to complete the data interaction, so that the digital identity terminal with the main control chip communicates with the encryption chip through the SPI interface, which can meet the transmission rate requirements of the digital identity application of large data volume encryption, and the data link layer protocol is used to realize the unification of the data interaction mode, and solve the compatibility problem between different devices and encryption chips. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a flow chart of the first embodiment of the data interaction method based on the SPI interface of the present invention; Figure 2 This is a schematic diagram of a digital identity terminal embodiment of an embodiment of a data interaction method based on an SPI interface of the present invention; Figure 3 This is a schematic diagram of SPI interface connection according to an embodiment of a data interaction method based on an SPI interface of the present invention; Figure 4 A circuit diagram of an embodiment of a data interaction method based on an SPI interface of the present invention; Figure 5 It is a flow chart of the second embodiment of the data interaction method based on the SPI interface of the present invention; Figure 6 It is a flow chart of the third embodiment of the data interaction method based on the SPI interface of the present invention; Figure 7 A structural block diagram of an embodiment of the main control chip of the present invention; Figure 8 This is a structural block diagram of an embodiment of an encryption chip of the present invention; Fig. 9 This is a structural block diagram of the first embodiment of the data interaction system based on the SPI interface of the present invention.
[0016] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0017] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0018] The embodiment of the present invention provides a data interaction method based on the SPI interface. Figure 1 , Figure 1 The figure is a flow chart of a first embodiment of a data interaction method based on an SPI interface of the present invention.
[0019] A data interaction method based on an SPI interface is applied to a main control chip, wherein the main control chip has an SPI interface and a USB interface, wherein the SPI interface includes an INT control pin, and the data interaction method based on the SPI interface includes the following steps: Step S10: When the INT control pin is at a preset level, a protocol synchronization data block is sent to the encryption chip, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block.
[0020] It should be noted that the executor of this embodiment is the main control chip in the data interaction system based on the SPI interface. The data interaction system based on the SPI interface includes a main control chip and an encryption chip. The main control chip is located in the digital identity terminal.
[0021] It is understandable that most existing digital identity terminals and encryption chips communicate using the ISO7816 interface, which has a low transmission rate and cannot meet the transmission rate requirements of large data volume encryption in digital identity applications; the SPI interface technology solution used in the traditional industrial field does not propose a hardware solution that can communicate with a smart encryption card or encryption chip with an SPI interface; most SPI communication solutions do not explain the data link layer protocol, resulting in different SPI interface devices being unable to unify on the link layer protocol, and in complex systems, different devices may use different link layer protocols, which brings a huge amount of compatibility work to device development; the data link layer protocol proposed in some solutions is quite different from the data link layer protocol used in the traditional chip industry, and cannot be used for APDU instruction transmission, integrity verification and transmission error correction of smart encryption cards or encryption chips. In order to solve the above problems, a data interaction method based on the SPI interface of this embodiment is proposed. The digital identity terminal in this embodiment has an SPI interface and an embedded data link layer protocol. This terminal can interact with the encryption chip through the SPI interface to make the integration between the two easier. Taking into account the differences in the implementation of SPI interface functions of different microcontroller units (MCUs), a data link layer protocol is proposed in this embodiment. During the data interaction process, the terminal parses the link layer protocol to complete functions such as data block interaction, integrity verification, and error correction.
[0022] It should be understood that the SPI interface digital identity terminal with a complete link layer protocol proposed in this embodiment is used in an implementation example of a digital identity application based on a 5G super SIM. Figure 2 As shown, the digital identity terminal and the contactless card reader are connected to each other through a USB interface, and the mobile terminal, such as a mobile phone, communicates with the card reader through an NFC interface and finally transmits data to the digital identity terminal. Obviously, the mobile phone NFC can also transmit data to the digital identity terminal through other links, such as the digital identity terminal directly receiving data through a contactless antenna, the digital identity terminal connecting to the card reader through Bluetooth, SPI, I2C, ISO7816 and other interfaces, which are not limited in this embodiment.
[0023] In the specific implementation, considering the possible MCU differences, in order to reduce power consumption, increase flexibility and scalability, this embodiment adds an INT control pin to the original SPI four-wire protocol, which is used by the smart encryption card or encryption chip to notify the terminal whether it can receive or send data at this time. When the terminal device detects that the INT pin is at a low level, it can perform data sending operations, and when it detects that the INT pin is at a high level, it can perform data receiving operations. The connection is as follows: Figure 3 shown.
[0024] It should be noted that the main control chip used in the hardware part of the digital identity terminal is an MCU chip with an SPI interface and a USB interface, which is used to provide the hardware implementation of the USB physical interface and the SPI physical interface, and uses the GPIO interface of the main control chip as the INT signal. The schematic diagram is as follows: Figure 4 The main control chip is connected to the smart encryption card or encryption chip through the SPI interface. The SPI interface includes MOSI, MISO data pins, SCLK clock pin, SS chip select pin and INT control pin. The INT control pin is used to receive notifications sent by the smart encryption card or encryption chip, and determine whether data can be received or sent based on the notifications.
[0025] It can be understood that the design of the data link layer protocol is specifically as follows: the data frame of the data link layer protocol includes the NAD field, PCB field, Len field, INF field and CRC field arranged in sequence, as shown in Table 1, where the LEN and CRC fields are both high byte first. One byte stores an 8-bit unsigned number, and the stored value range is 0-255. The NAD field is used to identify the sender and receiver of the data, where the high half byte is the sender identifier and the low half byte is the receiver identifier. The CRC field is used to calculate all the data of the NAD field, PCB field, LEN field and INF field, that is, all the data of NAD+PCB+LEN+INF, using the polynomial x16+x12+x5+1 for calculation, x is any hexadecimal number, the initial vector is 0xFFFF, and the calculation result needs to be XORed with 0xFFFF. The CRC field can solve the integrity and consistency verification problems during data transmission.
[0026] Table 1
[0027] In the specific implementation, the data link layer protocol includes three types of data blocks: I block, R block and S block. The I block and some S blocks include PCB field, LEN field, INF field and CRC field arranged in sequence. The R block does not contain the INF field. The three data blocks are distinguished by the PCB field, as shown in Table 2. The I block is used to actually send data. The seventh bit of the PCB field of the I block is used to identify the block number. The block number is 0 or 1 and is used cyclically in sequence. The fifth bit is used to identify whether there is a block link. If there is a link, it indicates that the INF of this I block and the INF of the next I block are continuous information. Its classification is shown in Table 3. The R block is used to notify the other party when receiving abnormal data or to notify the other party of successful reception when receiving chain blocks. The fifth bit of the PCB field of the R block is used to identify the block number, which is 0 or 1 and is used cyclically in sequence. The second and first bits of the PCB field are used to identify the receiving status. 00 indicates that the previous I block was successfully received when chaining blocks, 01 indicates that a CRC check error occurred when the previous block was received, and 10 indicates that other errors other than CRC check errors occurred when the previous block was received. The LEN field of the R block is 0x0000, and there is no INF domain. Its classification is shown in Table 4. The S block is used for protocol control, and its classification is shown in Table 5. The S (WTX) block is used to send to the main control chip within the preset waiting time during the execution of the encryption chip to notify the main control chip to continue waiting. The S (RESYNCH) block is used for the main control chip to initiate the protocol synchronization function. The S (IFS) block is used to modify the maximum length of the INF of the I block. The S (ABORT) block is used to terminate the transmission of subsequent chain blocks during data transmission.
[0028]
[0029]
[0030] It should be noted that the main control chip sends data means that the main control chip sends APDU instructions to the encryption chip, and the main control chip receives data means that the encryption chip returns APDU responses to the main control chip. The format of the data sent by the main control chip is shown in Table 6. Among them, the length of LEN is 2 bytes, and its value is the length of the subsequent data field. The high byte is sent first and then the low byte. For example, the main control chip sends data (00A40400080011223344556677), the host (main control chip) is identified as 1, and the slave (encryption chip) is identified as 5. The data flow is as follows: 0x15+0x00+0x00+0x0D+0x00+0xA4+0x04+0x00+0x08+0x00+0x11+0x22+0x33+0x44+0x55+0x66+0x77+CRCH+CRCL. The format of the data received by the main control chip is the same as Table 6. For the APDU command sent by the above main control chip, the intelligent encryption chip returns data (LEN byte data 844A6F…9000). The main control chip sends a read command, and the data flow is as follows: 0x51+0x00+LENH+LENL+0x84+0x4A+0x6F+…+0x90+0x00+CRCH+A+CRCL.
[0031] Table 6
[0032] It can be understood that the preset level refers to a low level. When the INT control pin of the main control chip is at the preset level, it indicates that the APDU instruction can be sent. When the INT control pin of the main control chip is at a high level, it is confirmed that the response returned by the encryption chip can be received. When the APDU instruction needs to be sent and the INT control pin of the main control chip is detected to be at a high level, an error is reported and the encryption chip is reset; after the APDU instruction is sent, if the preset waiting time is exceeded and no response is received from the encryption chip, an error is reported and the encryption chip is reset.
[0033] In a specific implementation, when the INT control pin is at a preset level, a protocol synchronization data block is sent to the encryption chip. The protocol synchronization data block refers to an S (RESYNCH) block. The encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block.
[0034] It should be noted that in order to ensure the accuracy of subsequent data interaction, it is necessary to ensure that the encryption chip has performed protocol synchronization. Furthermore, when the INT control pin is at a preset level, a protocol synchronization data block is sent to the encryption chip so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block. It also includes: if no protocol response information is received within the second time threshold, the step of sending the protocol synchronization data block to the encryption chip again so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; obtaining the number of repeated executions; when the number of repeated executions exceeds the preset number threshold, a protocol synchronization error is reported, and the encryption chip is reset.
[0035] It can be understood that the second time threshold refers to the time threshold corresponding to the set S block, and the encryption chip should return an S (RESYNCH) block response. After sending the protocol synchronization data block to the encryption chip, the encryption chip should return an S (RESYNCH) block response, and the S (RESYNCH) block response returned by the encryption chip is the protocol response information. In this embodiment, the second time threshold is set to 0.24 seconds. If the protocol response information returned by the encryption chip is not received within the second time threshold, the protocol synchronization data block is sent to the encryption chip again. The number of times the protocol synchronization data block is sent to the encryption chip again is the number of repeated executions. If the number of repeated executions exceeds the preset number threshold and the correct S (RESYNCH) block response has not been received, a protocol synchronization error is reported and the encryption chip is reset.
[0036] Step S20: upon receiving the protocol response information fed back by the encryption chip, the current state is set to a waiting-to-send state.
[0037] It should be noted that if the protocol response information fed back by the encryption chip is received, the main control chip sets the current state to a state to be sent. In order to ensure the accuracy of the state adjustment, the current state is further set to a state to be sent, including: setting the block numbers of the content receiving data block and the content sending data block to preset values according to the protocol response information to obtain a data block reset result; and determining that the current state is a state to be sent according to the data block reset result.
[0038] It can be understood that the content receiving data block is the R block, the content sending data block is the I block, the preset value is set to 0 in this embodiment, the sending block number and the receiving block number are set to 0 according to the protocol response information, and the data block reset result is obtained. When the data block reset result is that the block number reset is completed, it is determined that the current state has been adjusted to the waiting state. The corresponding block number in the content sending data block is the sending block number, and the corresponding block number in the content receiving data block is the receiving block number.
[0039] Step S30: sending the content sending data block to the encryption chip according to the waiting-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information.
[0040] It should be noted that, when I block is sent to the encryption chip in the waiting state, the encryption chip will return corresponding response information after receiving I block. The response information returned by the encryption chip after receiving I block is the content response information.
[0041] Step S40: when the content response information received within the first time threshold is successful reception information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, and data interaction is completed according to the adjustment result.
[0042] It should be noted that the first time threshold refers to the set waiting response time threshold. In the present embodiment, the first time threshold is set to 0.3 seconds. Successfully received information refers to the correct I block response returned by the encryption chip. If the content response information received within the first time threshold is a correct I block response, and the block number in the successfully received information is consistent with the received block number, and when the link information in the I block indicates that there is no link, the main control chip flips all the content receiving block number and the content sending block number, and the APDU instruction interaction ends, and the next instruction is ready to be sent. The link information refers to the identification information of the fifth bit of the PCB field of the I block.
[0043] It is understandable that in the process of controlling the data flow between the main control chip and the encryption chip, when an error occurs, the attempt to send R(N) for error correction is three times. After all failures: the main control chip should report an error and reset the encryption chip; the encryption chip maintains the current state and no longer responds to any block except the correct I block. The S(RESYNCH) block can only be initiated by the main control chip, and the encryption chip should reply to the S(RESYNCH) block after receiving it correctly. The main control chip attempts synchronization three times. After all failures, the encryption chip should be reset. The maximum number of retransmissions of other S blocks is also set to three times.
[0044] The data interaction method based on the SPI interface of this embodiment is applied to the main control chip, including: when the INT control pin is at a preset level, sending a protocol synchronization data block to the encryption chip, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; when receiving the protocol response information fed back by the encryption chip, setting the current state to a waiting-to-send state; sending a content sending data block to the encryption chip according to the waiting-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information; when the content response information received within the first time threshold is successfully received information, adjusting the content receiving block number and the content sending block number according to the link information of the content sending data block, and completing the data interaction according to the adjustment result. Through the above method, the main control chip sends the protocol synchronization data block to the encryption chip, the encryption chip synchronizes the data link layer protocol, and sends the content sending data block to the encryption chip in the waiting state. When the content response information received within the first time threshold is the successful reception information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, so as to complete the data interaction, so that the digital identity terminal with the main control chip communicates with the encryption chip through the SPI interface, which can meet the transmission rate requirements of the digital identity application of large data volume encryption, and the data link layer protocol is used to realize the unification of the data interaction mode, and solve the compatibility problem between different devices and encryption chips.
[0045] Reference Figure 5 , Figure 5 The figure is a flow chart of a second embodiment of a data interaction method based on an SPI interface according to the present invention.
[0046] Based on the above first embodiment, after step S30 in the data interaction method based on the SPI interface of this embodiment, the following further includes: Step S31: when the content response information received within the first time threshold is transmission termination information, terminating the transmission of the content transmission data block according to the transmission termination information, and sending a transmission termination response to the encryption chip.
[0047] It should be noted that after sending the I block, before receiving the S(WTX) block request returned by the encryption chip within the first time threshold, if the S(ABORT) request returned by the encryption chip is received, it means that the total length of the INF domain sent to the encryption chip exceeds the receiving capacity of the encryption chip, and the S(ABORT) response should be sent to terminate the data transmission and report an error. The S(ABORT) request returned by the encryption chip is the transmission termination information, and the S(ABORT) response sent by the main control chip is the transmission termination response.
[0048] Step S32: When the content response information received within the first time threshold is length modification information, determine the domain target length according to the length modification information, modify the information domain length according to the domain target length, and send a length modification response to the encryption chip.
[0049] It should be noted that after sending the I block, before receiving the S(WTX) block request returned by the encryption chip within the first time threshold, if the S(IFS) request returned by the encryption chip is received, it means that the total length of the INF domain sent to the encryption chip exceeds the default IFSC. In this embodiment, the encryption chip receives the maximum length of the INF domain of a single block, which is 261 bytes by default when powered on. Then the IFSC should be adjusted according to the INF in the received S(IFS), and an S(IFS) response should be sent to the encryption chip. The INF domain of the subsequent block sent by the main control chip should not be greater than the new IFSC. The S(IFS) request returned by the encryption chip is the length modification information, and the IFSC attached to the length modification information is the domain target length. The S(IFS) response sent by the main control chip to the encryption chip is the length modification response.
[0050] Step S33: When the content response information received within the first time threshold is reception response information, the response block number is determined according to the reception response information, and a block number comparison is performed according to the response block number and the content sending block number. When the block number comparison results are consistent, the content sending data block is resent.
[0051] It should be noted that after sending the I block, before receiving the S(WTX) block request returned by the encryption chip within the first time threshold, if the R(N) block response returned by the encryption chip is received, it is determined whether the block number of the received R(N) block response is consistent with the sent block number. If they are consistent (there is an error R block), the previous instruction is retransmitted. The R(N) block response returned by the encryption chip is the receiving response information, and the block number of the R(N) block response is the response block number.
[0052] It can be understood that if the block number of the received R(N) block response is inconsistent with the sent block number and is in the link (error-free R block), the sent block number is flipped and the next linked I block is sent. If an R block response that does not meet the above two conditions is received, the R(N) block is sent to the encryption chip to report an error.
[0053] In a specific implementation, after sending the I block, before receiving the S(WTX) block request returned by the encryption chip within the first time threshold, if the next APDU instruction is continued to be sent, the encryption chip returns an R(N) block error.
[0054] It should be noted that in order to ensure a correct response to the information fed back by the encryption chip and to ensure the normal data interaction, further, the content sending data block is sent to the encryption chip according to the waiting-to-send status, so that the encryption chip receives the content sending data block and feeds back content response information, and also includes: when the content response information received within the first time threshold is a timeout waiting information, the timeout waiting information is verified; when the information verification result is that the timeout waiting information is the preset waiting information, the waiting time is reset according to the timeout waiting information and the first time threshold, and a timeout waiting response is sent to the encryption chip; when the information verification result is that the timeout waiting information is not the preset waiting information, a receiving response data block is sent to the encryption chip according to the timeout waiting information, so that the encryption chip re-feeds back the timeout waiting information according to the receiving response data block.
[0055] It can be understood that after sending the I block, after receiving the S(WTX) block request returned by the encryption chip within the first time threshold, the returned S(WTX) block request is verified. If the information verification result is that the timeout waiting information is the preset waiting information, it means that the returned S(WTX) block request is the correct S(WTX) block request. At this time, the waiting time is reset according to the timeout waiting information and the first time threshold. If the information verification result is that the timeout waiting information is not the preset waiting information, it means that the returned S(WTX) block request is an incorrect S(WTX) block request, and then the R(N) block is sent to the encryption chip, requiring the encryption chip to re-feed back the timeout waiting information. The S(WTX) block request returned by the encryption chip is the timeout waiting information, the correct S(WTX) block request is the preset waiting information, and the R(N) block sent by the main control chip is the receiving response data block.
[0056] In a specific implementation, in order to ensure the accuracy of the adjustment of the content receiving block number and the content sending block number, further, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, including: determining whether the content sending data block has a link according to the link information of the content sending data block; when the content sending data block has a link, flipping and adjusting the content receiving block number and maintaining the content sending block number; when the content sending data block does not have a link, flipping and adjusting both the content receiving block number and the content sending block number.
[0057] It should be noted that if the correct I block response returned by the encryption chip is received, the block number is consistent with the received block number, and the link information of the I block is used to determine whether the I block has a link. If the I block has a link, the content receiving block number is flipped, the content sending block number is kept unchanged, and the error-free R (N) block is sent to the encryption chip to prepare for receiving the next I block. If the total length of INF exceeds the maximum receiving capacity, an S (ABORT) request is sent to terminate the reception. If there is no link in the I block, the APDU instruction interaction ends, and the content receiving block number and the content sending block number are all flipped to prepare for sending the next instruction.
[0058] It is understandable that if the main control chip receives other blocks or an error occurs, it sends the R(N) block to the encryption chip, requiring the encryption chip to retransmit. The error refers to errors such as CRC, NAD, block number error or failure to receive error-free R blocks in the link.
[0059] In this embodiment, when the content response information received within the first time threshold is transmission termination information, the transmission of the content sending data block is terminated according to the transmission termination information, and a transmission termination response is sent to the encryption chip; when the content response information received within the first time threshold is length modification information, the domain target length is determined according to the length modification information, the information domain length is modified according to the domain target length, and a length modification response is sent to the encryption chip; when the content response information received within the first time threshold is reception response information, the response block number is determined according to the reception response information, the block number is compared according to the response block number and the content sending block number, and when the block number comparison results are consistent, the content sending data block is resent. In the above manner, the accuracy of data interaction is guaranteed.
[0060] refer to Figure 6 , Figure 6 The figure is a flow chart of a third embodiment of a data interaction method based on an SPI interface of the present invention.
[0061] The data interaction method based on the SPI interface of this embodiment is applied to an encryption chip, comprising the following steps: Step S01: upon receiving a power-on instruction sent by a main control chip, the level of the INT control pin of the main control chip is adjusted so that the INT control pin of the main control chip is at a preset level, and a protocol synchronization data block is fed back. The main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin.
[0062] It should be noted that the execution subject of this embodiment is an encryption chip in a data interaction system based on an SPI interface. The data interaction system based on an SPI interface includes a main control chip and an encryption chip, and the main control chip is located in a digital identity terminal. The digital identity terminal in this embodiment has an SPI interface and an embedded data link layer protocol. This terminal can perform command interaction with the encryption chip through the SPI interface, making the integration between the two easier. Considering the differences in the implementation of SPI interface functions of different microcontroller units (MCUs), a data link layer protocol is proposed in this embodiment. The terminal parses the link layer protocol during the data interaction process to complete the interaction of data blocks, integrity verification, and error correction.
[0063] It is understandable that most existing digital identity terminals and encryption chips communicate using the ISO7816 interface, which has a low transmission rate and cannot meet the transmission rate requirements of large data volume encryption in digital identity applications; the SPI interface technology solution used in the traditional industrial field does not propose a hardware solution that can communicate with a smart encryption card or encryption chip with an SPI interface; most SPI communication solutions do not explain the data link layer protocol, resulting in different SPI interface devices being unable to unify on the link layer protocol, and in complex systems, different devices may use different link layer protocols, which brings a huge amount of compatibility work to device development; the data link layer protocol proposed in some solutions is quite different from the data link layer protocol used in the traditional chip industry, and cannot be used for APDU instruction transmission, integrity verification and transmission error correction of smart encryption cards or encryption chips. In order to solve the above problems, a data interaction method based on the SPI interface of this embodiment is proposed. The digital identity terminal in this embodiment has an SPI interface and an embedded data link layer protocol. This terminal can interact with the encryption chip through the SPI interface to make the integration between the two easier. Taking into account the differences in the implementation of SPI interface functions of different microcontroller units (MCUs), a data link layer protocol is proposed in this embodiment. During the data interaction process, the terminal parses the link layer protocol to complete functions such as data block interaction, integrity verification, and error correction.
[0064] In the specific implementation, considering the possible MCU differences, in order to reduce power consumption, increase flexibility and scalability, this embodiment adds an INT control pin to the original SPI four-wire protocol, which is used by the smart encryption card or encryption chip to notify the terminal whether it can receive or send data at this time. When the terminal device detects that the INT pin is at a low level, it can perform data sending operations, and when it detects that the INT pin is at a high level, it can perform data receiving operations. The connection is as follows: Figure 3 shown.
[0065] It should be noted that the main control chip used in the hardware part of the digital identity terminal is an MCU chip with an SPI interface and a USB interface, which is used to provide the hardware implementation of the USB physical interface and the SPI physical interface, and uses the GPIO interface of the main control chip as the INT signal. The schematic diagram is as follows: Figure 4 The main control chip is connected to the smart encryption card or encryption chip through the SPI interface. The SPI interface includes MOSI, MISO data pins, SCLK clock pin, SS chip select pin and INT control pin. The INT control pin is used to receive notifications sent by the smart encryption card or encryption chip, and determine whether data can be received or sent based on the notifications.
[0066] It can be understood that the design of the data link layer protocol is specifically as follows: the data frame of the data link layer protocol includes the NAD field, PCB field, Len field, INF field and CRC field arranged in sequence, as shown in Table 1, where the LEN and CRC fields are both high byte first. One byte stores an 8-bit unsigned number, and the stored value range is 0-255. The NAD field is used to identify the sender and receiver of the data, where the high half byte is the sender identifier and the low half byte is the receiver identifier. The CRC field is used to calculate all the data of the NAD field, PCB field, LEN field and INF field, that is, all the data of NAD+PCB+LEN+INF, using the polynomial x16+x12+x5+1 for calculation, x is any hexadecimal number, the initial vector is 0xFFFF, and the calculation result needs to be XORed with 0xFFFF. The CRC field can solve the integrity and consistency verification problems during data transmission.
[0067] Table 1
[0068] In the specific implementation, the data link layer protocol includes three types of data blocks: I block, R block and S block. The I block and some S blocks include PCB field, LEN field, INF field and CRC field arranged in sequence. The R block does not contain the INF field. The three data blocks are distinguished by the PCB field, as shown in Table 2. The I block is used to actually send data. The seventh bit of the PCB field of the I block is used to identify the block number. The block number is 0 or 1 and is used cyclically in sequence. The fifth bit is used to identify whether there is a block link. If there is a link, it indicates that the INF of this I block and the INF of the next I block are continuous information. Its classification is shown in Table 3. The R block is used to notify the other party when receiving abnormal data or to notify the other party of successful reception when receiving chain blocks. The fifth bit of the PCB field of the R block is used to identify the block number, which is 0 or 1 and is used cyclically in sequence. The second and first bits of the PCB field are used to identify the receiving status. 00 indicates that the previous I block was successfully received when chaining blocks, 01 indicates that a CRC check error occurred when the previous block was received, and 10 indicates that other errors other than CRC check errors occurred when the previous block was received. The LEN field of the R block is 0x0000, and there is no INF domain. Its classification is shown in Table 4. The S block is used for protocol control, and its classification is shown in Table 5. The S (WTX) block is used to send to the main control chip within the preset waiting time during the execution of the encryption chip to notify the main control chip to continue waiting. The S (RESYNCH) block is used for the main control chip to initiate the protocol synchronization function. The S (IFS) block is used to modify the maximum length of the INF of the I block. The S (ABORT) block is used to terminate the transmission of subsequent chain blocks during data transmission.
[0069]
[0070]
[0071] It should be noted that the preset level refers to a low level. When the power-on command of the main control chip is received, the INT control pin of the main control chip is set to a low level. After the block sent by the main control chip is received and processed, when a response is returned to the main control chip, the INT control pin of the main control chip is set to a high level. After the main control chip completely reads the data that the encryption chip expects to return, the INT control pin of the main control chip is set to a low level, waiting to receive the next instruction.
[0072] It can be understood that when the INT control pin is at a preset level, the main control chip sends a protocol synchronization data block to the encryption chip, and the protocol synchronization data block refers to an S (RESYNCH) block.
[0073] Step S02: Synchronize the data link layer protocol according to the protocol synchronization data block and generate protocol response information.
[0074] It should be noted that, initially, the encryption chip sets the current receiving block number to 0, the current sending block number to 1, and the current state to the receiving state. When receiving the protocol synchronization data block sent by the main control chip, the data link layer protocol is synchronized based on the protocol synchronization data block, and an S (RESYNCH) block response is generated. The generated S (RESYNCH) block response is the protocol response information.
[0075] Step S03: sending the protocol response information to the main control chip, so that the main control chip sets the current state to a waiting-to-send state according to the protocol response information, and sends the content data block to the encryption chip according to the waiting-to-send state.
[0076] It should be noted that the protocol response information is sent to the main control chip, and the main control chip sets the current state to the waiting state according to the protocol response information, and sends the content sending data block to the encryption chip, and the content sending data block refers to the I block.
[0077] Step S04: Generate content response information according to the content sending data block, and send the content response information to the main control chip, so that when the content response information received by the main control chip within the first time threshold is successfully received information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, and complete the data interaction according to the adjustment result.
[0078] It should be noted that after receiving the I block, the encryption chip will generate corresponding content response information and send the content response information to the main control chip. The first time threshold refers to the set waiting response time threshold. In the present embodiment, the first time threshold is set to 0.3 seconds. Successfully received information refers to the correct I block response returned by the encryption chip. If the content response information received within the first time threshold is a correct I block response, and the block number in the successfully received information is consistent with the received block number, when the link information in the I block indicates that there is no link, the main control chip will completely flip the content receiving block number and the content sending block number, and the APDU instruction interaction ends, and the next instruction is ready to be sent. The link information refers to the identification information of the fifth bit of the PCB field of the I block.
[0079] It can be understood that when the encryption chip receives the I block sent by the main control chip, it sets the S(WTX) block timer time to the first time threshold and transfers to the subsequent instruction processing. If it receives the S(RESYNCH) block sent by the chip master, it returns the S(RESYNCH) block response and restores to the initial state. If the S(IFS) block sent by the main control chip is received, the IFSD should be adjusted according to the INF in the received S(IFS). In this embodiment, the main control chip receives the maximum length of the INF field of a single block, which is 261 bytes by default when powered on, and sends an S(IFS) response. The INF field of the subsequent sent block should not be larger than the new IFSD.
[0080] In the specific implementation, if the encryption chip receives other blocks or an error occurs, it returns an R(N) block response to notify the error; if the correct I block sent by the main control chip is received, and the block number is consistent with the current receiving block number, it means that the reception is successful. If the I block has a link, the current receiving block number is flipped, and the R(N) block is sent to prepare for receiving the next block. If the I block has no link, the current receiving block number and the current sending block number are all flipped.
[0081] It should be noted that, after receiving the correct unlinked I block sent by the main control chip, the encryption chip sets the S(WTX) block timer time to the first time threshold and switches to subsequent instruction processing. At this time, if the instruction execution is completed, the INT control pin of the main control chip is pulled low to prepare to send the I block; if the R(N) block sent by the main control chip is received, the R(N) block response notification error is returned; if the S block sent by the main control chip is received, the R(N) block response notification error is returned; if the I block sent by the main control chip is received, the R(N) block response notification error is returned; if the preset time is reached, the INT control pin of the main control chip is pulled low, the S(WTX) block response is returned, and the main control chip is notified to continue waiting.
[0082] It can be understood that after the encryption chip returns the S(WTX) block response to the main control chip, if the instruction execution is completed, it will pull down the INT control pin of the main control chip and prepare to send the I block; if it receives the R(N) block sent by the main control chip, and the block number is consistent with the current sending block number, it will retransmit the S(WTX) block response; if other blocks are received or an error occurs, it will return the R(N) block response to notify the error.
[0083] In a specific implementation, after the encryption chip sends an I block to the main control chip, if it receives an I block sent by the main control chip, it determines whether the block number of the received I block is consistent with the current receiving block number. If they are inconsistent, it returns an R(N) block response notification error. If they are consistent, it flips the current receiving block number. If it receives an I block sent by the main control chip and the total length of the INF domain exceeds the receiving capacity of the main control chip, it sends S(ABORT) to request the main control chip to terminate the sending of the I block. After receiving the correct S(ABORT) response from the main control chip, the encryption chip Sending an R(N) block returns the sending right to the main control chip; if an R(N) block is received from the main control chip, determine whether the block number of the received R(N) block is consistent with the current sending block number. If they are consistent (there is an error), retransmit the I block; if they are inconsistent (no error) and are in the link, flip the sending block number and continue to send the next I block; if other blocks are received or an error occurs, return an R(N) block response to notify the error; if an S(RESYNCH) block is received from the main control chip, return an S(RESYNCH) block response and restore to the initial state. If an S (ABORT) request is received from the main control chip, it means that the total length of the INF field sent to the main control chip exceeds the receiving capacity of the main control chip, and an S (ABORT) response should be sent to terminate data transmission; if an S (IFS) block is received from the main control chip, the IFSD should be adjusted according to the INF in the received S (IFS). In this embodiment, the maximum length of the INF field of a single block received by the main control chip is 261 bytes by default upon power-on, and an S (IFS) response is sent. The INF field of subsequent sent blocks should not be larger than the new IFSD.
[0084] It should be noted that in the process of data flow control between the main control chip and the encryption chip, when an error occurs, the attempt to send R(N) for error correction is three times. After all failures: the main control chip should report an error and reset the encryption chip; the encryption chip maintains the current state and no longer responds to any block except the correct I block. The S(RESYNCH) block can only be initiated by the main control chip, and the encryption chip should reply to the S(RESYNCH) block after receiving it correctly. The main control chip attempts synchronization three times. After all failures, the encryption chip should be reset. The maximum number of retransmissions of other S blocks is also set to three times.
[0085] The data interaction method based on the SPI interface of the present embodiment is applied to an encryption chip, comprising: when receiving a power-on instruction sent by a main control chip, adjusting the level of an INT control pin of the main control chip so that the INT control pin of the main control chip is at a preset level, and feeding back a protocol synchronization data block, wherein the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin; synchronizing a data link layer protocol according to the protocol synchronization data block, and generating protocol response information; sending the protocol response information to the main control chip so that the main control chip sets a current state to a waiting state according to the protocol response information, and sends a content sending data block to the encryption chip according to the waiting state; generating content response information according to the content sending data block, and sending the content response information to the main control chip, so that when the content response information received by the main control chip within a first time threshold is successfully received information, adjusting a content receiving block number and a content sending block number according to link information of the content sending data block, and completing data interaction according to the adjustment result. Through the above method, the digital identity terminal with the main control chip can communicate with the encryption chip through the SPI interface, which can meet the transmission rate requirements of large data volume encryption in digital identity applications, and the data link layer protocol is used to unify the data interaction method, solving the compatibility problem between different devices and encryption chips.
[0086] In addition, refer to Figure 7 The embodiment of the present invention further provides a main control chip, the main control chip comprising: The sending module 01 is used to send a protocol synchronization data block to the encryption chip when the INT control pin is at a preset level, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block.
[0087] The processing module 02 is used to set the current state to a waiting-to-send state when receiving the protocol response information fed back by the encryption chip.
[0088] The sending module 01 is further used to send the content sending data block to the encryption chip according to the waiting-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information.
[0089] The adjustment module 03 is further configured to adjust the content receiving block number and the content sending block number according to the link information of the content sending data block when the content response information received within the first time threshold is successfully received information, and complete data interaction according to the adjustment result.
[0090] This embodiment sends a protocol synchronization data block to the encryption chip when the INT control pin is at a preset level, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; when receiving the protocol response information fed back by the encryption chip, the current state is set to a waiting-to-send state; according to the waiting-to-send state, a content sending data block is sent to the encryption chip, so that the encryption chip receives the content sending data block and feeds back content response information; when the content response information received within the first time threshold is successfully received information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, and data interaction is completed according to the adjustment result. Through the above method, the main control chip sends the protocol synchronization data block to the encryption chip, the encryption chip synchronizes the data link layer protocol, and sends the content sending data block to the encryption chip in the waiting state. When the content response information received within the first time threshold is the successful reception information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, so as to complete the data interaction, so that the digital identity terminal with the main control chip communicates with the encryption chip through the SPI interface, which can meet the transmission rate requirements of the digital identity application of large data volume encryption, and the data link layer protocol is used to realize the unification of the data interaction mode, and solve the compatibility problem between different devices and encryption chips.
[0091] In one embodiment, the sending module 01 is further configured to execute the step of sending the protocol synchronization data block to the encryption chip again if the protocol response information is not received within the second time threshold, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; Get the number of repeated executions; When the number of repeated executions exceeds a preset number threshold, a protocol synchronization error is reported and the encryption chip is reset.
[0092] In one embodiment, the sending module 01 is further configured to terminate the sending of the content sending data block according to the transmission termination information when the content response information received within the first time threshold is transmission termination information, and send a transmission termination response to the encryption chip; When the content response information received within the first time threshold is length modification information, determining a domain target length according to the length modification information, modifying the information domain length according to the domain target length, and sending a length modification response to the encryption chip; When the content response information received within the first time threshold is reception response information, the response block number is determined according to the reception response information, and a block number comparison is performed according to the response block number and the content sending block number. When the block number comparison results are consistent, the content sending data block is resent.
[0093] In one embodiment, the sending module 01 is further configured to verify the timeout waiting information when the content response information received within the first time threshold is timeout waiting information; When the information verification result is that the timeout waiting information is the preset waiting information, resetting the waiting time according to the timeout waiting information and the first time threshold, and sending a timeout waiting response to the encryption chip; When the information verification result is that the timeout waiting information is not the preset waiting information, a receiving response data block is sent to the encryption chip according to the timeout waiting information, so that the encryption chip re-feeds back the timeout waiting information according to the receiving response data block.
[0094] In one embodiment, the adjustment module 03 is further used to determine whether the content sending data block has a link based on the link information of the content sending data block; when the content sending data block has a link, the content receiving block number is flipped and adjusted to maintain the content sending block number; when the content sending data block does not have a link, both the content receiving block number and the content sending block number are flipped and adjusted.
[0095] In one embodiment, the processing module 02 is further used to set the block numbers of the content receiving data block and the content sending data block to preset values according to the protocol response information to obtain a data block reset result; According to the data block reset result, it is determined that the current state is a waiting-to-send state.
[0096] Since the main control chip adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0097] In addition, refer to Figure 8 The embodiment of the present invention further provides an encryption chip, the encryption chip comprising: The adjustment module 11 is used to adjust the level of the INT control pin of the main control chip when receiving the power-on instruction sent by the main control chip, so that the INT control pin of the main control chip is at a preset level, and feedback the protocol synchronization data block, the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin.
[0098] The synchronization module 12 is used to synchronize the data link layer protocol according to the protocol synchronization data block and generate protocol response information.
[0099] The sending module 13 is used to send the protocol response information to the main control chip, so that the main control chip sets the current state to the waiting state according to the protocol response information, and sends the content data block to the encryption chip according to the waiting state.
[0100] The generating module 14 is used to generate content response information according to the content sending data block, and send the content response information to the main control chip, so that when the content response information received by the main control chip within the first time threshold is successfully received information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, and the data interaction is completed according to the adjustment result.
[0101] This embodiment adjusts the level of the INT control pin of the main control chip when receiving a power-on instruction sent by the main control chip, so that the INT control pin of the main control chip is at a preset level, and feeds back a protocol synchronization data block, the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin; synchronizes the data link layer protocol according to the protocol synchronization data block, and generates protocol response information; sends the protocol response information to the main control chip, so that the main control chip sets the current state to a waiting state according to the protocol response information, and sends a content sending data block to the encryption chip according to the waiting state; generates content response information according to the content sending data block, and sends the content response information to the main control chip, so that when the content response information received by the main control chip within the first time threshold is successfully received information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, and data interaction is completed according to the adjustment result. Through the above method, the digital identity terminal with the main control chip can communicate with the encryption chip through the SPI interface, which can meet the transmission rate requirements of large data volume encryption in digital identity applications, and the data link layer protocol is used to unify the data interaction method, solving the compatibility problem between different devices and encryption chips.
[0102] Since the encryption chip adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0103] In addition, refer to Fig. 9 The embodiment of the present invention further proposes a data interaction system based on the SPI interface, and the data interaction system based on the SPI interface includes a main control chip 21 and an encryption chip 22.
[0104] Since the data interaction system based on the SPI interface adopts all the technical solutions of all the above embodiments, it at least has all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0105] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.
[0106] In addition, for technical details not fully described in this embodiment, reference can be made to the data interaction method based on the SPI interface provided in any embodiment of the present invention, and will not be repeated here.
[0107] In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0108] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0109] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0110] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A data interaction method based on SPI interface, characterized in that: Applied to a main control chip, the main control chip has an SPI interface and a USB interface, the SPI interface includes an INT control pin, and the data interaction method based on the SPI interface includes: When the INT control pin is at a preset level, a protocol synchronization data block is sent to the encryption chip, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; When receiving the protocol response information fed back by the encryption chip, setting the current state to a waiting-to-send state; Sending the content sending data block to the encryption chip according to the ready-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information; When the content response information received within the first time threshold is successful reception information, the content reception block number and the content transmission block number are adjusted according to the link information of the content transmission data block, and the data interaction is completed according to the adjustment result.
2. The data interaction method based on the SPI interface as claimed in claim 1, characterized in that: When the INT control pin is at a preset level, after sending a protocol synchronization data block to the encryption chip so that the encryption chip performs synchronization of the data link layer protocol according to the protocol synchronization data block, the method further includes: If the protocol response information is not received within the second time threshold, the step of sending the protocol synchronization data block to the encryption chip is performed again, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; Get the number of repeated executions; When the number of repeated executions exceeds a preset number threshold, a protocol synchronization error is reported and the encryption chip is reset.
3. The data interaction method based on the SPI interface as claimed in claim 1, characterized in that: After sending the content sending data block to the encryption chip according to the ready-to-send state so that the encryption chip receives the content sending data block and feeds back content response information, the method further includes: When the content response information received within the first time threshold is transmission termination information, terminating the transmission of the content transmission data block according to the transmission termination information, and sending a transmission termination response to the encryption chip; When the content response information received within the first time threshold is length modification information, determining a domain target length according to the length modification information, modifying the information domain length according to the domain target length, and sending a length modification response to the encryption chip; When the content response information received within the first time threshold is reception response information, the response block number is determined according to the reception response information, and a block number comparison is performed according to the response block number and the content sending block number. When the block number comparison results are consistent, the content sending data block is resent.
4. The data interaction method based on the SPI interface as claimed in claim 1, characterized in that: After sending the content sending data block to the encryption chip according to the ready-to-send state so that the encryption chip receives the content sending data block and feeds back content response information, the method further includes: When the content response information received within the first time threshold is timeout waiting information, performing information verification on the timeout waiting information; When the information verification result is that the timeout waiting information is the preset waiting information, resetting the waiting time according to the timeout waiting information and the first time threshold, and sending a timeout waiting response to the encryption chip; When the information verification result is that the timeout waiting information is not the preset waiting information, a receiving response data block is sent to the encryption chip according to the timeout waiting information, so that the encryption chip re-feeds back the timeout waiting information according to the receiving response data block.
5. The data interaction method based on the SPI interface as claimed in claim 1, characterized in that: The adjusting the content receiving block number and the content sending block number according to the link information of the content sending data block comprises: Determine whether the content sending data block has a link according to the link information of the content sending data block; When the content sending data block has a link, the content receiving block number is flipped and adjusted to keep the content sending block number; When there is no link in the content sending data block, both the content receiving block number and the content sending block number are flipped and adjusted.
6. The data interaction method based on the SPI interface as claimed in claim 1, characterized in that: The step of setting the current state to a waiting-to-send state includes: According to the protocol response information, the block numbers of the content receiving data block and the content sending data block are set to preset values to obtain a data block reset result; According to the data block reset result, it is determined that the current state is a waiting-to-send state.
7. A data interaction method based on SPI interface, characterized in that: Applied to the encryption chip, the data interaction method based on the SPI interface includes: When receiving the power-on instruction sent by the main control chip, the level of the INT control pin of the main control chip is adjusted to make the INT control pin of the main control chip a preset level, and a protocol synchronization data block is fed back, the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin; Synchronize the data link layer protocol according to the protocol synchronization data block and generate protocol response information; Sending the protocol response information to the main control chip, so that the main control chip sets the current state to a waiting-to-send state according to the protocol response information, and sends the content data block to the encryption chip according to the waiting-to-send state; Generate content response information according to the content sending data block, and send the content response information to the main control chip, so that when the content response information received by the main control chip within a first time threshold is successfully received information, adjust the content receiving block number and the content sending block number according to the link information of the content sending data block, and complete data interaction according to the adjustment result.
8. A main control chip, characterized in that: The main control chip includes: A sending module, used for sending a protocol synchronization data block to the encryption chip when the INT control pin is at a preset level, so that the encryption chip synchronizes the data link layer protocol according to the protocol synchronization data block; A processing module, configured to set the current state to a waiting-to-send state upon receiving the protocol response information fed back by the encryption chip; The sending module is further used to send the content sending data block to the encryption chip according to the waiting-to-send state, so that the encryption chip receives the content sending data block and feeds back content response information; The adjustment module is further used to adjust the content receiving block number and the content sending block number according to the link information of the content sending data block when the content response information received within the first time threshold is successful reception information, and complete data interaction according to the adjustment result.
9. An encryption chip, characterized in that: The encryption chip comprises: The adjustment module is used to adjust the level of the INT control pin of the main control chip when receiving the power-on instruction sent by the main control chip, so that the INT control pin of the main control chip is at a preset level, and feedback the protocol synchronization data block, the main control chip has an SPI interface and a USB interface, and the SPI interface includes an INT control pin; A synchronization module, used to synchronize the data link layer protocol according to the protocol synchronization data block and generate protocol response information; A sending module, used for sending the protocol response information to the main control chip, so that the main control chip sets the current state to a waiting-to-send state according to the protocol response information, and sends the content and data block to the encryption chip according to the waiting-to-send state; A generating module is used to generate content response information according to the content sending data block, and send the content response information to the main control chip, so that when the content response information received by the main control chip within the first time threshold is successfully received information, the content receiving block number and the content sending block number are adjusted according to the link information of the content sending data block, and the data interaction is completed according to the adjustment result.
10. A data interaction system based on SPI interface, characterized in that: The data interaction system based on the SPI interface includes the main control chip as claimed in claim 8 and the encryption chip as claimed in claim 9.
