A USBKEY communication protocol automatic switching method and system
The automatic switching method and system based on the USBKEY communication protocol solves the problem of USBKEY not being able to switch automatically on different devices, and achieves intelligent protocol matching and improved ease of use.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-20
- Publication Date
- 2026-04-14
AI Technical Summary
Existing USB keys cannot automatically switch between different communication protocol host devices, resulting in inconvenience and poor usability.
This invention provides a method and system for automatic switching of USBKEY communication protocols. By activating actions and controlling protocol switching permissions, it enables automatic switching of different communication protocols, including smart card reader protocols and mass storage protocols.
The compatibility and ease of use of the USB key across different devices have been improved, and protocol switching and reactivation are supported, enhancing the product's adaptability and convenience.
Smart Images

Figure CN117640785B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information security technology, and in particular to a method and system for automatic switching of USBKEY communication protocols. Background Technology
[0002] With the advent of the intelligent information age, e-commerce has developed rapidly, and cryptographic devices and modules are being used by more and more users. As the number of users increases, USB keys, as secure storage media for cryptographic keys, are becoming increasingly widespread. Correspondingly, when USB keys are used, higher requirements are placed on their basic needs such as security, portability, and convenience.
[0003] USB KEY smart keys utilize both Mass Storage and CCID (Common Core Identifier) protocols, both of which are widely used and rapidly developing in daily life. While each protocol has its advantages and disadvantages, both also face scenarios where they cannot be used or recognized. For example, some machines disable USB flash drives for security reasons, and since USB flash drives use the Mass Storage protocol, USB keys using the same protocol will also be disabled. In such cases, only USB keys using the CCID protocol can be used. Similarly, some machines may not recognize smart card devices, requiring the use of the Mass Storage protocol. Therefore, the ease of use of USB KEY smart keys on various host devices cannot be guaranteed.
[0004] Therefore, how to develop a method and system for automatically switching USB key communication protocols on host devices with different communication protocols is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] This invention addresses the aforementioned research status and existing problems by providing a method and system for automatic switching of USBKEY communication protocols. This enables the USBKEY smart password key to intelligently match different host devices in different scenarios. It eliminates the hassle of returning the device to the factory to re-download the COS firmware due to firmware obfuscation or device incompatibility, significantly improving the usability of the USBKEY product.
[0006] This invention provides an automatic switching method for USBKEY communication protocols, wherein the USBKEY communication protocol is a communication protocol between the USBKEY and the host device, and the number of communication protocol modes of the USBKEY communication protocol is ≥2; the method includes the following steps:
[0007] Execute the activation action of the USBKEY communication protocol. If the main control device fails to recognize the USBKEY within a specified number of activation actions, switch the current USBKEY communication protocol mode.
[0008] The USBKEY communication protocol activation action includes the execution of inserting the USBKEY into the host device and powering it on.
[0009] Preferably, the communication protocol mode includes a smart card reader protocol and a mass storage protocol.
[0010] Preferably, if the main control device fails to recognize the USBKEY within a specified number of activation actions, the communication protocol mode of the current USBKEY is switched, including the following steps:
[0011] Set the threshold N for the number of activation actions to switch the USBKEY communication protocol mode, where N > 1;
[0012] Execute the activation action of inserting the USBKEY into the host device, and count the number of activation actions i.
[0013] When i reaches N and the main control device does not recognize the UEBKEY, the communication protocol mode of the current USBKEY is switched after the N+1th activation action is performed.
[0014] Preferably, it also includes the step of enabling or disabling protocol switching permissions:
[0015] Determine whether the protocol switching permission is enabled. If so, perform the following steps: If the main control device fails to recognize the USBKEY within the specified number of activation actions, switch the communication protocol mode of the current USBKEY.
[0016] Preferably, the process also includes a step to determine the communication status of the USB key:
[0017] Determine whether a communication link has been established between the USBKEY and the host device. If so, disable the protocol switching permission. The conditions for determining whether a communication link has been established include: successful data interaction between the host device and the USBKEY.
[0018] Preferably, the step of determining the USBKEY communication status further includes:
[0019] Determine whether a communication link has been established between the USBKEY and the host device. If so, do not respond to the activation action.
[0020] Preferably, it also includes the step of switching the communication protocol mode of the current USB key when the protocol switching permission is disabled:
[0021] The USBKEY receives a specified command code sent to it by the adapted master control device, and performs the activation action of the USBKEY communication protocol T times, where T≥1;
[0022] The command code includes instructions to perform the following steps:
[0023] The instruction to enable protocol switching permissions, and the instruction to set the number of times the activation action has been executed to a number within a specified range N and save it, where N>1;
[0024] T = N - number of times executed + 1.
[0025] This invention also discloses an automatic switching system for USB key communication protocols according to the aforementioned automatic switching method, wherein the USB key communication protocol is a communication protocol between the USB key and the host device, and the number of communication protocol modes of the USB key communication protocol is ≥2; it includes: a communication mode configuration register, a protocol activation status register, and a control unit; wherein,
[0026] The communication mode configuration register is used to identify the communication protocol mode of the current USBKEY;
[0027] The protocol activation status register is used to identify the current number of times the activation action has been executed; the USBKEY communication protocol activation action includes the execution action of the host device recognizing the inserted USBKEY;
[0028] The control unit is used to detect the activation action of the USBKEY communication protocol, send an update instruction to the protocol activation status register to indicate the current number of times the activation action has been executed, and determine whether the host device has recognized the USBKEY if the number of times the activation action has been executed is within a specified range. If not, it sends a switching instruction to the communication mode configuration register to indicate the current communication protocol mode.
[0029] Preferably, it further includes: a protocol switching system configuration register, used to identify the protocol switching permission status of the USB KEY communication protocol, including: a closed state or an open state; when the automatic switching permission status is open, the control unit performs the following steps:
[0030] If the activation action is executed within a specified number of times, the main control device determines whether it has recognized the USBKEY. If not, it sends a switching instruction for the current communication protocol mode to the communication mode configuration register.
[0031] Preferably, it further includes: a communication status configuration register, used to identify the communication status of the USBKEY, including: an established communication link status and a non-established communication link status. The conditions for establishing a communication link include: the host device successfully interacting with the USBKEY; when the USBKEY communication status is an established communication link status, the control unit performs the following steps:
[0032] Send a command to the protocol switching system configuration register to update the protocol switching permission status to the off state.
[0033] The present invention has the following advantages over the prior art:
[0034] This invention constructs a method and system for automatically switching communication protocols for USB keys. It supports automatic switching between smart card reader protocols, mass storage protocols, and other protocols, improving the compatibility between the USB key and the host device. It also features protocol switching reactivation functionality and supports external command control to open or close the automatic communication protocol switching system. This invention can automatically match servers with various protocols, increasing product usability. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely embodiments of the present invention, and those skilled in the art can obtain other drawings based on the provided drawings without creative effort.
[0036] Figure 1 This is a flowchart of an automatic switching method for USBKEY communication protocol provided in an embodiment of the present invention;
[0037] Figure 2 This is a register configuration diagram of the USBKEY communication protocol automatic switching system provided in this embodiment of the invention;
[0038] Figure 3 This is a schematic diagram illustrating the automatic switching of system register initialization state of the USBKEY communication protocol provided in an embodiment of the present invention;
[0039] Figure 4 This is a schematic diagram of the register state after the USBKEY has been plugged in and unplugged three times in an embodiment of the present invention.
[0040] Figure 5 This is a schematic diagram of the register state after switching the communication protocol mode according to an embodiment of the present invention;
[0041] Figure 6 This is a schematic diagram of the register state after establishing a communication link, provided in an embodiment of the present invention.
[0042] Figure 7 This is a schematic diagram of the command code format provided in an embodiment of the present invention;
[0043] Figure 8 This is a diagram of register flag information during reactivation provided in an embodiment of the present invention;
[0044] Figure 9 This is a diagram of the register flag information after reactivation provided in an embodiment of the present invention. Detailed Implementation
[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0046] like Figure 1 As shown, the first aspect of this invention provides a method for automatically switching USBKEY communication protocols. The USBKEY communication protocol is a communication protocol between the USBKEY and the host device, and the number of communication protocol modes of the USBKEY communication protocol is ≥2. The method includes the following steps:
[0047] Execute the activation action of the USBKEY communication protocol. If the host device fails to recognize the USBKEY within the specified number of activation actions, switch the current USBKEY communication protocol mode.
[0048] The USBKEY communication protocol activation process includes inserting the USBKEY into the host device and powering it on. After the USBKEY is powered on, the host device recognizes the inserted USBKEY.
[0049] In one embodiment, the activation action includes repeatedly plugging and unplugging the USB key on the host device.
[0050] In one embodiment, the communication protocol modes include smart card reader protocols and mass storage protocols.
[0051] In one embodiment, if the host device fails to recognize the USBKEY after the activation action has been performed a specified number of times, the communication protocol mode of the current USBKEY is switched, including the following steps:
[0052] Set the threshold N for the number of activation actions to switch the USBKEY communication protocol mode, where N > 1;
[0053] Perform the activation action of inserting the USBKEY into the host device, and count the number of activation actions i.
[0054] When i reaches N and the host device does not recognize the UEBKEY, the communication protocol mode of the current USBKEY will be switched after the N+1th activation action is performed.
[0055] In one embodiment, the step of enabling or disabling protocol switching permissions is also included:
[0056] Determine if protocol switching permission is enabled. If so, perform the following steps: If the main control device fails to recognize the USBKEY within the specified number of activation actions, switch the communication protocol mode of the current USBKEY.
[0057] In one embodiment, the step of determining the USBKEY communication status is also included:
[0058] Determine whether a communication link has been established between the USBKEY and the host device. If so, disable protocol switching permission. The conditions for determining whether a communication link has been established include: successful data exchange between the host device and the USBKEY.
[0059] In this embodiment, the step of determining the communication status of the USBKEY further includes:
[0060] Determine whether a communication link has been established between the USBKEY and the host device. If so, do not respond to the activation action.
[0061] It should be noted that the communication status determines the protocol switching system status without human intervention. Once the USB key and the host device have completed pairing and can communicate normally, the protocol switching permission is turned off. At this time, the communication protocol is fixed, and the USB key communication mode is set to the corresponding communication protocol mode. Continuous plugging and unplugging of the USB key will not switch the communication protocol again, so as to ensure that the user is in a normal communication state during use and to ensure the correctness of communication.
[0062] In one embodiment, the method further includes the step of switching the communication protocol mode of the current USBKEY when protocol switching permission is disabled.
[0063] The USBKEY receives the specified command code sent to it by the adapted host device and executes the activation action of the USBKEY communication protocol T times, where T≥1;
[0064] The command code includes instructions to perform the following steps:
[0065] Commands to enable protocol switching permissions and commands to set the number of times the activation action has been executed to a number within a specified range N and save the result, where N > 1;
[0066] T = N - number of times executed + 1.
[0067] The second aspect of this invention provides a USBKEY communication protocol automatic switching system based on the USBKEY communication protocol automatic switching method of the first aspect. For the COS program of the same USBKEY, the differences between the various protocols mainly lie in the differences in the USB configuration descriptor, the protocol itself, and the communication messages. The configuration descriptor specifies the characteristics and capabilities of the USBKEY; each communication method corresponds to a different protocol, and the USBKEY's operation and processing methods are completely consistent, differing only in data processing. Therefore, by simply making judgments and distinctions at the USBKEY configuration descriptor, communication protocol, and USBKEY data processing points, the multiple communication protocols can be connected in series.
[0068] like Figure 2 As shown, the USBKEY communication protocol automatic switching system includes: a communication mode configuration register, a protocol activation status register, and a control unit; among which,
[0069] The communication mode configuration register is used to identify the communication protocol mode of the current USBKEY;
[0070] The protocol activation status register is used to identify the current number of times the activation action has been executed; the USBKEY communication protocol activation action includes the execution action of the host device recognizing the inserted USBKEY;
[0071] The control unit is used to detect the activation action of the USBKEY communication protocol, send an update instruction to the protocol activation status register to indicate the current number of times the activation action has been executed, and determine whether the host device has recognized the USBKEY if the number of times the activation action has been executed is within a specified range. If not, it sends a switching instruction to the communication mode configuration register to indicate the current communication protocol mode.
[0072] In practice, the communication mode configuration register identifies whether the current communication protocol is a smart card reader protocol or a mass storage protocol, etc. After the host system successfully interacts with the USB key, it sets this register according to the adopted communication protocol. Once this register is set, the host system and the USB key communicate using the communication protocol set in this register. A value of 1 in the communication mode configuration register indicates Mode 1: Smart Card Reader Protocol; a value of 2 indicates Mode 2: Mass Storage Protocol.
[0073] The number of consecutive plug-in / plug-out attempts by the user is the value in the protocol activation status register. This system and method can set an activation threshold and calculate when the threshold is exceeded, indicating that the USBKEY can automatically switch protocols. This register is related to the communication status configuration register; once the communication status configuration register is set to normal communication, this register will no longer respond to the protocol activation status.
[0074] In one embodiment, it further includes: a protocol switching system configuration register, used to identify the protocol switching permission status of the USBKEY communication protocol, including: a closed state or an open state; when the automatic switching permission status is open, the control unit performs the following steps:
[0075] Determine whether the host device has recognized the USBKEY if the activation action has been executed within a specified number of times. If not, send a switching instruction for the current communication protocol mode to the communication mode configuration register.
[0076] In practice, this register indicates whether the USBKEY communication protocol automatic switching system is in a disabled or enabled state. When the protocol switching system configuration register is enabled, automatic protocol switching is allowed; otherwise, it is disabled.
[0077] In one embodiment, the system further includes: a communication status configuration register for identifying the USBKEY communication status, including: an established communication link status and a non-established communication link status. The conditions for establishing a communication link include: successful data interaction between the host device and the USBKEY. When the USBKEY communication status is an established communication link status, the control unit performs the following steps:
[0078] Send a command to the protocol switching system configuration register to update the protocol switching permission status to the off state.
[0079] In practice, this register indicates whether the USBKEY has successfully communicated. Once the host and USBKEY have successfully interacted, the communication status configuration register is set to "successfully communicating." Once this register is set to "successfully communicating," the protocol switching system configuration register is disabled, and the automatic protocol switching function is turned off. To subsequently re-enable the automatic protocol switching function, the host system that has successfully interacted with the USBKEY must send a COS command to the USBKEY. Sending the COS command to the USBKEY sets the protocol switching system configuration register to "on," enabling the automatic protocol switching function, and correspondingly, the communication status configuration register is set to "successfully communicating." After successful communication resumes, the communication status configuration register is set to "successfully communicating," the protocol switching system configuration register is set to "off," and the automatic protocol switching function is turned off.
[0080] In this embodiment of the invention, the protocol switching system configuration register, communication status configuration register, communication mode configuration register, and protocol activation status register are configured in non-volatile memory, so that the data is not lost when power is off.
[0081] like Figure 3As shown, the newly manufactured USBKEY protocol switching system configuration register is in the open state; the communication mode configuration register is configured to be in the state of not being able to communicate normally; the communication mode configuration register is set to the smart card reader protocol by default, and the initial value of the protocol activation status register is 0.
[0082] The following is an example of using the above registers to implement automatic communication protocol switching:
[0083] When a user inserts the USB key into the host device for the first time, and the host device does not recognize the USB key, if the user then inserts and removes the USB key three times consecutively (the activation threshold set in the new factory default protocol activation status register is 3), and the host still fails to enumerate the USB key, the value in the protocol activation status register will be 3, indicating that the set activation threshold has been reached. Therefore, the default setting is that the machine does not recognize the smart card reader protocol. At this time, the communication protocol automatically switches the status of various system registers as follows: Figure 4 As shown.
[0084] Insert the USBKEY back into the host device. The communication mode configuration register switches to the mass storage protocol, and the corresponding program on the card also switches to the mass storage protocol. When the communication mode configuration register switches protocols, the value of the protocol activation status register starts from 0 until it reaches the set activation threshold again, at which point the protocol switch occurs again. At this time, the communication protocol automatically switches the status of each register in the system as follows: Figure 5 As shown.
[0085] When the host device successfully recognizes the USB key and can communicate normally with it, the communication protocol is determined and will not be changed. The protocol switching system configuration register is closed, and the communication status configuration register is configured to a normal communication state, indicating that a communication link has been established. The communication mode configuration register is set to the corresponding communication protocol. Because no further insertion or removal occurred before the protocol switching system configuration register was closed, the value of the protocol activation status register remains unchanged. Continuous insertion or removal of the USB key will not trigger protocol switching. At this time, the states of the registers in the automatic communication protocol switching system are as follows: Figure 6 As shown.
[0086] The following is an example of implementing the reactivation function using the above registers:
[0087] To prevent users from changing the main control device midway or needing to switch communication protocols for other reasons, the protocol switching system can be reopened via the protocol switching system reactivation function after it has been shut down. This function reopens the protocol switching system configuration register; simply sending a specified command code to the USBKEY from the compatible main control device enables or disables the protocol switching system configuration register.
[0088] The protocol switching procedure is the same as that for a newly manufactured USB key to be paired with a host device. After the host device enumerates the USB key or successfully performs a password operation, the protocol switching is completed, and the system shuts down again. This process can be repeated, and the activation threshold of the protocol activation status register can be configured according to user needs. The command code format is as follows: Figure 7 As shown.
[0089] If the host sends the instruction for automatic switching of communication protocol system status control to the USB KEY as "0x80 0x0a0x01 0x03 0x00", the COS program will find the corresponding interface function based on the first two command codes "800a". Within the interface function, the program will open or close the protocol switching system configuration register by judging the value of Para1.
[0090] When Para1 is 1, the Protocol Switching System Configuration Register is enabled; when Para1 is 0, the Protocol Switching System Configuration Register is disabled.
[0091] The value of Para2 is the value of the required protocol activation status register. Therefore, Para2 must be greater than or equal to 0 and less than or equal to the set activation threshold (e.g., a threshold of 3). After the command is successfully sent, the register states of the automatic communication protocol switching system within the USBKEY are configured accordingly based on the command. After executing this command, the host device receives a return code, such as "9000," indicating that the protocol switching system has been successfully reactivated. The protocol switching system configuration register is now open, allowing for re-matching of the communication protocol until communication is successful again. At this time, the register states of the automatic communication protocol switching system are as follows: Figure 8 As shown.
[0092] After unplugging and plugging the USB key again, the communication protocol will switch to the smart card reader protocol. The communication mode configuration register will be set to the smart card reader protocol, and intra-card communication will also use the smart card reader protocol. After normal communication, the protocol switching system configuration register will be closed. At this time, the communication protocol will automatically switch the state of each register in the system as follows: Figure 9 As shown.
[0093] The above provides a detailed description of the automatic switching method and system for USBKEY communication protocols provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
[0094] In this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, without necessarily requiring or implying any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method for automatically switching USBKEY communication protocols, wherein the USBKEY communication protocol is a communication protocol between the USBKEY and the host device, and the number of communication protocol modes of the USBKEY communication protocol is ≥2; characterized in that: Includes the following steps: Determine if protocol switching permission is enabled. If so, execute the activation action for the USBKEY communication protocol. If the host device fails to recognize the USBKEY within a specified number of activation actions, switch the current USBKEY's communication protocol mode, including: Set the threshold N for the number of activation actions to switch the USBKEY communication protocol mode, where N > 1; Execute the activation action of inserting the USBKEY into the host device, and count the number of activation actions i. When i reaches N and the main control device does not recognize the UEBKEY, the communication protocol mode of the current USBKEY is switched after the N+1th activation action is performed. The USBKEY communication protocol activation action includes the action of inserting the USBKEY into the host device and powering it on; It also includes the steps for determining the USBKEY communication status: Determine whether a communication link has been established between the USBKEY and the host device. If so, disable the protocol switching permission. The conditions for determining whether a communication link has been established include: successful data interaction between the host device and the USBKEY.
2. The automatic switching method for USBKEY communication protocol according to claim 1, characterized in that, The communication protocol modes include smart card reader protocol and mass storage protocol.
3. The method for automatic switching of USBKEY communication protocol according to claim 1, characterized in that, The steps for determining the communication status of the USBKEY also include: Determine whether a communication link has been established between the USBKEY and the host device. If so, do not respond to the activation action.
4. The method for automatic switching of USBKEY communication protocol according to claim 1, characterized in that, It also includes the steps for switching the communication protocol mode of the current USB key when protocol switching permissions are disabled: The USBKEY receives a specified command code sent to it by the adapted master control device, and performs the activation action of the USBKEY communication protocol T times, where T≥1; The command code includes instructions to perform the following steps: The instruction to enable protocol switching permissions, and the instruction to set the number of times the activation action has been executed to a number within a specified range N and save it, where N>1; T = N - number of times executed + 1.
5. A USBKEY communication protocol automatic switching system according to any one of claims 1-4, wherein the USBKEY communication protocol is a communication protocol between the USBKEY and the host device, and the number of communication protocol modes of the USBKEY communication protocol is ≥2; characterized in that, include: Communication mode configuration register, protocol activation status register, and control unit; among which, The communication mode configuration register is used to identify the communication protocol mode of the current USBKEY; The protocol activation status register is used to identify the current number of times the activation action has been executed; the USBKEY communication protocol activation action includes the execution action of the host device recognizing the inserted USBKEY; The control unit is used to determine whether protocol switching permission is enabled. If so, it detects the activation action of the USBKEY communication protocol, sends an update instruction for the current execution count of the activation action to the protocol activation status register, and determines whether the host device recognizes the USBKEY if the execution count of the activation action is within a specified range. This includes: Set the threshold N for the number of activation actions to switch the USBKEY communication protocol mode, where N > 1; Execute the activation action of inserting the USBKEY into the host device, and count the number of activation actions i. When i reaches N and the main control device does not recognize the UEBKEY, the communication protocol mode of the current USBKEY is switched after the N+1th activation action is performed. If not, a switching instruction for the current communication protocol mode is sent to the communication mode configuration register; It also includes the steps for determining the USBKEY communication status: Determine whether a communication link has been established between the USBKEY and the host device. If so, disable the protocol switching permission. The conditions for determining whether a communication link has been established include: successful data interaction between the host device and the USBKEY.
6. The USBKEY communication protocol automatic switching system according to claim 5, characterized in that, Also includes: The protocol switching system configuration register is used to identify the protocol switching permission status of the USB KEY communication protocol, including: off or on. When the automatic permission switching state is enabled, the control unit performs the following steps: If the activation action is executed within a specified number of times, the main control device determines whether it has recognized the USBKEY. If not, it sends a switching instruction for the current communication protocol mode to the communication mode configuration register.
7. The USBKEY communication protocol automatic switching system according to claim 5, characterized in that, Also includes: A communication status configuration register is used to identify the communication status of the USBKEY, including: established communication link status and not established communication link status. The conditions for establishing a communication link include: successful data interaction between the host device and the USBKEY. When the USBKEY communication status is established, the control unit executes the following steps: Send a command to the protocol switching system configuration register to update the protocol switching permission status to the off state.
Citation Information
Patent Citations
Method and system for dynamically switching equipment arrangement
CN101266590A
Method for automatically identifying custom protocol and MODBUS protocol
CN112788032A