CN108920389B - Method and device for dynamically matching protocol type and application of multi-protocol USB device - Google Patents

Method and device for dynamically matching protocol type and application of multi-protocol USB device Download PDF

Info

Publication number
CN108920389B
CN108920389B CN201810748683.7A CN201810748683A CN108920389B CN 108920389 B CN108920389 B CN 108920389B CN 201810748683 A CN201810748683 A CN 201810748683A CN 108920389 B CN108920389 B CN 108920389B
Authority
CN
China
Prior art keywords
application
module
protocol
communication
instruction
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810748683.7A
Other languages
Chinese (zh)
Other versions
CN108920389A (en
Inventor
陆舟
于华章
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Feitian Technologies Co Ltd
Original Assignee
Feitian Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Feitian Technologies Co Ltd filed Critical Feitian Technologies Co Ltd
Priority to CN201810748683.7A priority Critical patent/CN108920389B/en
Publication of CN108920389A publication Critical patent/CN108920389A/en
Application granted granted Critical
Publication of CN108920389B publication Critical patent/CN108920389B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/10Program control for peripheral devices
    • G06F13/102Program control for peripheral devices where the programme performs an interfacing function, e.g. device driver
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/382Information transfer, e.g. on bus using universal interface adapter
    • G06F13/385Information transfer, e.g. on bus using universal interface adapter for adaptation of a particular data processing system to different peripheral devices

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Communication Control (AREA)

Abstract

The invention discloses a method and a device for dynamically matching the protocol type and the application of a multi-protocol USB device, wherein the method comprises the following steps: the equipment reports the own equipment protocol type to the upper computer; waiting for receiving an instruction from an upper computer, and if the instruction is a binding protocol instruction, acquiring a protocol identifier and an application identifier from the binding protocol instruction; selecting a communication application corresponding to the application identifier; binding the equipment protocol type corresponding to the protocol identifier with the communication application corresponding to the application identifier, and setting the equipment protocol type of the equipment according to the equipment protocol type of the bound communication application; if the command is a unbinding protocol command, acquiring a protocol identifier and an application identifier from the unbinding protocol command; unbinding the equipment protocol type corresponding to the protocol identifier and the communication application corresponding to the application identifier; and setting the own device protocol type according to the default device protocol type and the device protocol type of the bound communication application. The invention enhances the applicability of the equipment and has good user experience.

Description

Method and device for dynamically matching protocol type and application of multi-protocol USB device
Technical Field
The invention relates to the field of information security, in particular to a method and equipment for dynamically matching the protocol type and the application of a multi-protocol USB device.
Background
With the rapid development of internet technology, the types of USB Devices are also gradually increasing, and according to the protocol types supported by the Devices, the USB Devices may be classified into USB Devices supporting HID (human Interface Device), USB Devices supporting CCID (USB Chip/Smart Card Interface Device-USB) protocol, USB Devices supporting SCSI (Small Computer System Interface) protocol, Device types supporting other USB protocols, and USB Devices supporting multiple protocols; according to the classification of applications supported by the device, the USB device can be divided into a single-application USB device and a multi-application USB device, in the prior art, most USB devices are in operation, the device protocol type and the application are pre-associated, that is, the device can only access the pre-associated application in the device through one device protocol, so that the applicability of the device is limited, and the user experience is poor.
Disclosure of Invention
The invention provides a method and equipment for dynamically matching the protocol type and the application of a multi-protocol USB device, which solve the technical problem.
The invention provides a method for dynamically matching the protocol type of a multi-protocol USB device with an application, wherein the application is installed on the device; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the method comprises the following steps:
step s 1: the equipment reports one or more of the own equipment protocol types to the upper computer;
step s 2: the device waits for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type, after the instruction is received, the channel receiving the instruction is used as a current protocol channel, the type of the instruction received through the current protocol channel is judged, and if the instruction received through the current protocol channel is a binding protocol instruction, the step s3 is executed; if the instruction received through the current protocol channel is a unbinding protocol instruction, executing step s 6; if the command received through the current protocol channel is a USB communication command, execute step s 8;
step s 3: the device acquires a protocol identifier and an application identifier from the binding protocol instruction;
step s 4: the equipment selects a communication application corresponding to the application identifier;
step s 5: the equipment binds the equipment protocol type corresponding to the protocol identifier with the communication application corresponding to the application identifier, returns a binding success response to the upper computer through the current protocol channel, sets the equipment protocol type of the equipment according to the equipment protocol type of the bound communication application, and returns to the step s 2;
step s 6: the equipment acquires a protocol identifier and an application identifier from the unbinding protocol instruction;
step s 7: the equipment unbinds the equipment protocol type corresponding to the protocol identifier and the communication application corresponding to the application identifier, and returns an unbinding success response to the upper computer through the current protocol channel; setting the own device protocol type according to the default device protocol type and the device protocol type bound with the communication application, and returning to the step s 2;
step s 8: the equipment obtains a communication instruction from the USB communication instruction, and sends the communication instruction to a communication application bound with an equipment protocol type corresponding to the current protocol channel; receiving a communication response returned by the application; and packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step s 2.
The invention also provides a method for dynamically matching the protocol type of the multi-protocol USB equipment with the application, wherein the application is installed on the equipment; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the method comprises the following steps:
step r 1: the equipment reports the equipment protocol type of the equipment to the upper computer;
step r 2: the device waits for receiving an instruction from an upper computer through a channel corresponding to the reported device protocol type, after the instruction is received, the channel receiving the instruction is used as a current protocol channel, the type of the instruction received through the current protocol channel is judged, and if the instruction received through the current protocol channel is a protocol switching instruction, the step r3 is executed; if the command received through the current protocol channel is a USB communication command, executing step r 6; if the instruction received through the current protocol channel is a USB application selection instruction, executing a step r 7;
step r 3: the equipment sets the protocol type of the equipment according to the protocol identification in the protocol switching instruction; organizing a protocol switching response according to the equipment protocol type corresponding to the current protocol channel, and returning the protocol switching response to the upper computer through the current protocol channel; returning to the step r 2;
step r 6: the equipment obtains a communication instruction from the USB communication instruction and sends the communication instruction to the currently selected application; receiving a communication response returned by the application; packaging a communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response, and returning the USB communication response to the upper computer through the current protocol channel; returning to the step r 2;
step r 7: the device obtains a selected application instruction from the USB selected application instruction, and sends the selected application instruction to an application corresponding to an application identifier in the selected application instruction; receiving a select application response; organizing the selected application response according to the device protocol type corresponding to the current protocol channel to obtain a USB selected application response, returning the USB selected application response to the upper computer through the current protocol channel, and returning to the step r 2.
The invention also provides a multi-protocol USB device with the device protocol type dynamically matched with the application, and the application is installed on the device; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the apparatus comprises: the device comprises a reporting protocol type module, a first receiving module, a first judging module, a first obtaining module, a first selecting application module, a first binding module, a first returning module, a first setting module, a second obtaining module, a first unbinding module, a second setting module, a third obtaining module, a first sending module, a second receiving module and a first packaging module;
the report protocol type module is used for reporting one or more equipment protocol types of the equipment to the upper computer after the equipment is inserted into the upper computer;
the first receiving module is used for waiting for receiving the instruction from the upper computer through a channel corresponding to the reported device protocol type;
the first judging module is used for taking the channel receiving the instruction as a current protocol channel after the first receiving module receives the instruction, and judging the type of the instruction received by the current protocol channel;
the first obtaining module is configured to obtain a protocol identifier and an application identifier from the binding protocol instruction when the first determining module determines that the instruction received through the current protocol channel is the binding protocol instruction;
the first selection application module is used for selecting the communication application corresponding to the application identifier acquired by the first acquisition module;
the first binding module is configured to bind, after the first selected application module selects the communication application corresponding to the application identifier acquired by the first acquisition module, the device protocol type corresponding to the protocol identifier acquired by the first acquisition module and the communication application corresponding to the application identifier acquired by the first acquisition module;
the first returning module is used for returning a binding success response to the upper computer through the current protocol channel; returning a successful unbinding response to the upper computer through the current protocol channel; the USB communication response obtained by the first packaging module is returned to the upper computer through the current protocol channel;
the first setting module is configured to set the device protocol type of the device according to the device protocol type of the bound communication application after the first binding module binds the device protocol type corresponding to the protocol identifier acquired by the first acquiring module and the communication application corresponding to the application identifier acquired by the first acquiring module;
the second obtaining module is configured to obtain a protocol identifier and an application identifier from the unbinding protocol instruction when the first determining module determines that the instruction received through the current protocol channel is the unbinding protocol instruction;
the first unbinding module is configured to unbind the device protocol type corresponding to the protocol identifier acquired by the second acquiring module and the communication application corresponding to the application identifier acquired by the second acquiring module;
the second setting module is configured to set the device protocol type of the device according to the default device protocol type and the device protocol type of the bound communication application after the first unbinding module unbinds the device protocol type corresponding to the protocol identifier acquired by the second acquiring module and the communication application corresponding to the application identifier acquired by the second acquiring module;
the third obtaining module is used for obtaining a communication instruction from the USB communication instruction when the first judging module judges that the instruction received through the current protocol channel is the USB communication instruction;
the first sending module is configured to send the communication instruction obtained by the third obtaining module to a communication application bound to a device protocol type corresponding to a current protocol channel;
the second receiving module is used for receiving a communication response returned by the communication application bound with the equipment protocol type corresponding to the current protocol channel;
and the first packaging module is used for packaging the communication response received by the second receiving module according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response.
The invention also provides a multi-protocol USB device with the device protocol type dynamically matched with the application, and the application is installed on the device; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the apparatus comprises: the device comprises a reporting protocol type module, a first receiving module, a first judging module, a first setting module, a first returning module, a first obtaining module and a second obtaining module;
the reporting protocol type module is used for reporting the equipment protocol type of the equipment to the upper computer after the equipment is inserted into the upper computer;
the first receiving module is used for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type;
the first judging module is used for taking the channel receiving the instruction as a current protocol channel after the first receiving module receives the instruction, and judging the type of the instruction received by the current protocol channel;
the first setting module is used for setting the own equipment protocol type according to the protocol identifier in the protocol switching instruction when the first judging module judges that the instruction received through the current protocol channel is the protocol switching instruction;
the first returning module is used for organizing a protocol switching response according to the equipment protocol type corresponding to the current protocol channel and returning the protocol switching response to the upper computer through the current protocol channel; the USB communication response is returned to the upper computer through the current protocol channel; returning the USB selection application response to the upper computer through the current protocol channel;
the first obtaining module is used for obtaining a communication instruction from the USB communication instruction and sending the communication instruction to the currently selected application when the first judging module judges that the instruction received through the current protocol channel is the USB communication instruction; receiving a communication response returned by the application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response;
the second obtaining module is used for obtaining a selected application instruction from the USB selected application instruction and sending the selected application instruction to an application corresponding to an application identifier in the selected application instruction when the first judging module judges that the instruction received through the current protocol channel is the USB selected application instruction; receiving a select application response; and organizing the selected application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selected application response.
The invention has the beneficial effects that: the invention provides a method and equipment for dynamically matching a multi-protocol USB equipment protocol type with an application.
Drawings
Fig. 1 is a flowchart of a method for dynamically matching a protocol type of a multi-protocol USB device with an application according to embodiment 1 of the present invention;
fig. 2 is a flowchart of a method for dynamically matching a protocol type of a multi-protocol USB device with an application according to embodiment 2 of the present invention;
fig. 3 is a flowchart of a method for dynamically matching a protocol type of a multi-protocol USB device with an application according to embodiment 3 of the present invention;
fig. 4 is a flowchart illustrating an operation of a communication application according to embodiments 3 and 4 of the present invention;
fig. 5 is an operation flowchart of step 315 in a method for dynamically matching a protocol type of a multi-protocol USB device with an application according to embodiment 3 of the present invention;
fig. 6 is a flowchart of a method for dynamically matching a protocol type of a multi-protocol USB device with an application according to embodiment 4 of the present invention;
fig. 7 is a block diagram of a multi-protocol USB device with dynamically matched device protocol types and applications according to embodiment 5 of the present invention;
fig. 8 is a block diagram of a multi-protocol USB device with a device protocol type dynamically matched to an application according to embodiment 6 of the present invention.
Detailed description of the invention
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example 1
The embodiment provides a method for dynamically matching a protocol type of a multi-protocol USB device with an application, as shown in fig. 1, the method includes:
step 101: the equipment reports the own equipment protocol type to the upper computer;
in this embodiment, the device is specifically a USB device, and the device protocol type reported by the device to the upper computer is one or more (more than two) of the USB protocol types supported by the device.
Specifically, the device acquires the device protocol type according to the device protocol type parameter of the device, and reports one or more (more than two) of the device protocol types of the device to the upper computer according to the acquired device protocol type.
The initial value of the equipment protocol type parameter is matched with the default equipment protocol type, the default equipment protocol type can be one or more, and when the equipment is inserted into the computer for the first time, the equipment reports the default equipment protocol type to the upper computer.
For example: when the equipment is inserted into the computer for the first time, the equipment reports the default equipment protocol type to the upper computer as the HID protocol type; or when the equipment is inserted into the computer for the first time, the equipment reports the default equipment protocol type to the upper computer as the HID protocol type and the CCID protocol type.
Step 102: the equipment waits for receiving an instruction from the upper computer, judges the type of the instruction after receiving the instruction from the upper computer through the current protocol channel, and executes the step 103 if the instruction is a binding protocol instruction; if the instruction is an unbind protocol instruction, executing step 108; if the command is a USB communication command, go to step 111; if the command is a USB application selection command, go to step 114;
in this embodiment, the device waits for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type, and when receiving the instruction, the channel receiving the instruction of the upper computer is used as the current protocol channel.
In this embodiment, the type of the judgment instruction is specifically: and judging the type of the instruction received through the current protocol channel according to the effective data of the instruction, wherein the effective data in the instruction is an Application Protocol Data Unit (APDU) in the instruction.
Specifically, the device waits for receiving an instruction from the upper computer, after receiving the instruction from the upper computer through the current protocol channel, the device analyzes the instruction according to the device protocol type corresponding to the current protocol channel to obtain effective data in the instruction, and if data on the first three bytes of the effective data is a first preset character string, the instruction is a binding protocol instruction, and step 103 is executed; if the data in the first three bytes of the valid data is the second preset character string, the instruction is a unbinding protocol instruction, and then step 108 is executed; if the first three bytes of the valid data are the third predetermined character string, the command is a USB selection application command, and step 114 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 111 is executed.
In this embodiment, the first preset character string may be: 80E 100; the second predetermined character may be: 80E 101; the third predetermined string may be 00a 404.
More specifically: the method comprises the steps that the equipment waits for receiving an instruction from an upper computer, when the instruction from the upper computer is received through a current protocol channel, the instruction is analyzed according to the equipment protocol type corresponding to the current protocol channel, data on a first preset position in the instruction are obtained and are required to be used as effective data length, data with the data length being the effective data length are obtained from data on a second preset position in the instruction, the obtained data are used as effective data, and if the data on the first three bytes of the effective data are first preset character strings, the instruction is a binding protocol instruction, and step 103 is executed; if the data in the first three bytes of the valid data is the second preset character string, the instruction is a unbinding protocol instruction, and then step 108 is executed; if the first three bytes of the valid data are the third predetermined character string, the command is a USB selection application command, and step 114 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 111 is executed.
In this embodiment, if the current protocol channel is an HID protocol channel corresponding to the HID protocol, the first preset position may be, but is not limited to, a seventh byte in the instruction, and the second preset position may be, but is not limited to, an eighth byte in the instruction; if the current protocol channel is a CCID protocol channel corresponding to the CCID protocol, the first preset location may be, but is not limited to, a second byte in the instruction, and the second preset location may be, but is not limited to, an eleventh byte in the instruction; if the current protocol channel is a SCSI protocol channel corresponding to a SCSI protocol, the first predetermined location may be, but is not limited to, a ninth byte in the instruction, and the second predetermined location may be, but is not limited to, a thirty-second byte in the instruction.
For example: the device waits for receiving the instruction from the upper computer, when receiving the instruction 0000000183000 d 80e 1000008 a 0000006472 f 0001 cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc from the upper computer through the HID protocol channel, according to the HID protocol parsing instruction corresponding to the HID protocol channel, data "0 d" in the seventh byte in the instruction is acquired and is used as the valid data length, data with the data length being the valid data length is acquired from the data in the eighth byte in the instruction, the acquired data 80E 1000008 a 0000006472 f 0001 is used as the valid data, and if the data in the first three bytes of the valid data is the first preset character string 80E100, the instruction is the binding protocol instruction, and step 102 is executed.
Another example is: the equipment waits for receiving an instruction from an upper computer, when the instruction 6f 0d 000000003 e 00000080 e 1010008 a 0000006472 f 0001 from the upper computer is received through a CCID protocol channel, the instruction is analyzed according to the CCID protocol corresponding to the CCID protocol channel, data '0 d' on the second byte in the instruction is obtained and is used as an effective data length, data with the data length being the effective data length is obtained from data on the eleventh byte in the instruction, and the obtained data is 80e 1010008 a0
000006472 f 0001 as valid data, if the data in the first three bytes of the valid data is the second predetermined string 80E 101, the instruction is the unbind protocol instruction and step 108 is executed.
For example, when the device waits for receiving an instruction from the upper computer, receives an instruction 55534243 c 80945870 d 00000000000 a ff 45504153530000005500000000000000 a 4040008 a 0000006472 f 0001 from the upper computer through the SCSI protocol channel, and parses the instruction according to the SCSI protocol corresponding to the SCSI protocol channel, obtains data "0 d" in the ninth byte in the instruction and please use the data as an effective data length, obtains data with the data length being the effective data length from the data in the thirty second byte in the instruction, uses the obtained data 00a 4040008 a 0000006472 f 0001 as effective data, and if the data in the first three bytes of the effective data is the third preset character string 00a 404, the instruction is the USB selection application instruction, and step 114 is executed.
It should be further noted that, if the current protocol channel is an SCSI protocol channel corresponding to an SCSI protocol, after receiving an instruction from the upper computer through the current protocol channel, analyzing the instruction according to the device protocol type corresponding to the current protocol channel, and determining whether the type of the instruction is an instruction for the upper computer to send data to the device, if so, acquiring data at a first preset position in the instruction and please use the data as an effective data length, starting to acquire data with the effective data length from the last data at a second preset position in the instruction, and using the acquired data as effective data, otherwise, executing a corresponding operation.
Step 103: the device acquires a protocol identifier and an application identifier from the binding protocol instruction;
specifically, the device acquires data on the fourth section in the valid data of the binding protocol instruction, and uses the data as a protocol identifier; and taking the data on the fifth byte in the effective data of the binding protocol instruction as the data length of the application identifier, and acquiring the application identifier from the data field of the effective data of the binding protocol instruction according to the data length of the application identifier.
For example: the device acquires the data 00 on the fourth section in the valid data 80E 1000008A 0000006472F 0001 of the binding protocol instruction, and uses the data as a protocol identifier; taking the data 08 on the fifth byte in the valid data of the binding protocol instruction as the data length of the application identifier, and acquiring the data "A0000006472F 0001" with the data length of 8 bytes from the data field A000000006472F 0001 of the valid data of the binding protocol instruction as the application identifier.
In this embodiment, 00 is a protocol identifier corresponding to the HID protocol; 01 is a protocol identification corresponding to the CCID protocol; 02 is the protocol identification corresponding to the SCSI protocol.
Step 104: the equipment judges whether the equipment protocol type corresponding to the protocol identification is bound with the communication application, if so, the equipment reports an error to the upper computer through the current protocol channel and returns to the step 102; otherwise, go to step 105;
specifically, the device checks whether a binding identifier corresponding to the protocol identifier is set, if so, judges that the device protocol type corresponding to the protocol identifier is bound to the communication application, reports an error to the upper computer through the current protocol channel, and returns to the step 102; otherwise, it is determined that the device protocol type corresponding to the protocol identifier is not bound to the communication application, and step 105 is executed.
In this embodiment, a management application and a plurality of communication applications are installed in the device, and each device protocol type supported by the device may access the management application. The device can install each communication application through the management application, the management application is an application for managing each communication application, and each communication application is an application for realizing the functionality of the device: such as OTP applications, PKI applications, FIDO applications.
Step 105: the equipment organizes a selection application instruction comprising an application identifier, and sends the selection application instruction to an application corresponding to the application identifier;
specifically, the device takes the application identifier as data in a data field of the selected application instruction, adds an instruction header of the selected application instruction before the data field to obtain the selected application instruction including the application identifier, and sends the selected application instruction to the application corresponding to the application identifier.
For example: the device takes the application identifier 'A0000006472F 0001' as data in a data field of the selected application instruction, adds an instruction header '00A 4040008' of the selected application instruction before the data field, obtains the selected application instruction '00A 4040008A 0000006472F 0001' comprising the application identifier, and sends the selected application instruction to an application corresponding to the application identifier.
Step 106: the equipment receives the application selection response, judges whether the application selection is successful or not according to the application selection response, sets a binding identifier corresponding to the protocol identifier if the application selection is successful, organizes the binding success response according to the equipment protocol type corresponding to the current protocol channel, returns the binding success response to the upper computer through the current protocol channel, and executes the step 107; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 102;
the successful binding response is organized according to the device protocol type corresponding to the current protocol channel, and specifically comprises the following steps: and organizing and reporting the binding success response of the first success identification according to the equipment protocol type corresponding to the current protocol channel.
For example: the binding success acknowledgement 00000001830002900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 of the first successful identification 9000 is reported according to the HID protocol type organization corresponding to the HID protocol tunnel.
In this step, after setting the binding identifier corresponding to the protocol identifier, the method further includes: and correspondingly storing the application identifier and the protocol identifier in the binding protocol instruction.
Step 107: the equipment sets the own equipment protocol type according to the equipment protocol type bound with the communication application, resets the equipment and returns to the step 101;
specifically, the device updates the device type parameter of the device according to the device protocol type of the bound communication application; the device resets and returns to step 101.
Step 107 may specifically be: the equipment sets the own equipment protocol type according to the equipment protocol type of the current bound communication application, resets the equipment and returns to the step 101;
for example: the device sets the device protocol type of the device itself as the HID protocol type of the first communication application which is currently bound and corresponds to the application identifier 'A0000006472F 0001', resets the USB bus, reports the device protocol type of the device itself to the upper computer, and returns to the step 102.
Step 107 may also specifically be: the equipment sets the own equipment protocol type according to the equipment protocol types of all the bound communication applications, resets the equipment and returns to the step 101;
for example: the device sets the protocol type of the device to be the HID protocol type bound with the first communication application and the CCID protocol type bound with the second communication application, and resets the device.
In this embodiment, step 107 may be replaced by step b 1: the device judges whether the device protocol type of the current bound communication application is matched with the device protocol type reported currently, if so, the step 102 is returned; otherwise, setting the own device protocol type according to the device protocol type of the bound communication application, resetting the device, and returning to the step 101.
The step b1 is specifically as follows: the device judges whether the device protocol type of the currently bound communication application is one of the currently reported device protocol types, if so, the device protocol type of the currently bound communication application is judged to be matched with the currently reported device protocol type, and the step 102 is returned; otherwise, judging that the device protocol type of the currently bound communication application is not matched with the device protocol type reported currently, setting the device protocol type of the currently bound communication application as the device protocol type of all the device protocol types of the bound communication application, resetting the device, and returning to the step 101.
For example: if the device determines that the HID protocol type of the currently bound first communication application is one of the currently reported device protocol types (CCID protocol type and HID protocol type), the device determines that the device protocol type of the currently bound first communication application matches the currently reported device protocol type, and the process returns to step 102.
Step b1 may also be specifically: the device judges whether the device protocol type of the currently bound communication application is completely consistent with the device protocol type reported currently, if so, the device protocol type of the currently bound communication application is judged to be matched with the reported device protocol type, and the step 102 is returned; otherwise, judging that the device protocol type of the currently bound communication application is not matched with the device protocol type reported currently, setting the device protocol type of the currently bound communication application as the device protocol type of all the device protocol types of the bound communication application, resetting the device, and returning to the step 101.
For example: the device judges that the HID protocol type bound with the first communication application is not completely consistent with the current reported device protocol type (the HID protocol type and the CCID protocol type), judges that the device protocol type bound with the first communication application is not matched with the current reported device protocol type, sets the device protocol type of the device protocol type bound with the first communication application as the HID protocol type, resets the device, and returns to the step 101.
In this embodiment, the device in step b1 sets its own device protocol type according to the device protocol type of the bound communication application, specifically: the equipment sets the own equipment protocol type according to the equipment protocol type of the current bound communication application or the equipment sets the own equipment protocol type according to the equipment protocol types of all the bound communication applications.
Step 108: the equipment acquires a protocol identifier and an application identifier from the unbinding protocol instruction;
specifically, the device acquires data on the fourth section in the valid data of the unbinding protocol instruction, and uses the data as a protocol identifier; and taking the data on the fifth byte in the effective data as the data length of the application identifier, and acquiring the application identifier from the data field of the effective data of the unbinding protocol instruction according to the data length of the application identifier.
For example: the device acquires the data '00' on the fourth section in the valid data '80E 1010008A 0000006472F 0001' of the unbinding protocol instruction and takes the data as a protocol identifier; taking data "08" on the fifth byte of the valid data as the data length of the application identifier, and acquiring data "a 0000006472F 0001" with the data length of 8 bytes from the data field of the valid data as the application identifier.
Step 109: the device judges whether the device protocol type corresponding to the protocol identifier is bound with the communication application, if so, the step 110 is executed; otherwise, the current protocol channel of the channel reports errors to the upper computer and returns to the step 102;
specifically, the device checks whether a binding identifier corresponding to the protocol identifier is set, and if so, determines that the device protocol type corresponding to the protocol identifier is bound to the communication application, and then performs step 110; otherwise, judging that the equipment protocol type corresponding to the protocol identifier is not bound with the communication application, reporting an error to the upper computer by the current protocol channel of the channel, and returning to the step 102.
Step 110: resetting the binding identifier corresponding to the protocol identifier by the equipment, and returning a successful unbinding response to the upper computer through the current protocol channel; setting the own device protocol type according to the default device protocol type and the device protocol type bound with the communication application, resetting the device, and returning to the step 101;
in this step, the specific device protocol type setting according to the default device protocol type and the device protocol type bound with the communication application is as follows: the equipment judges whether the equipment protocol type of the bound communication application exists or not, and if so, the equipment protocol type of the equipment is set according to the equipment protocol type of the bound communication application; otherwise, setting the own device protocol type as the default device protocol type.
In this step, the device protocol type of the device is set according to the device protocol type of the bound communication application, specifically: and setting the own device protocol type as one or more of the device protocol types of the bound communication application.
In this step, after resetting the binding identifier corresponding to the protocol identifier, the method further includes: and deleting the application identifier stored corresponding to the protocol identifier.
Step 111: the device judges whether the device protocol type corresponding to the current protocol channel is bound with the communication application, if so, the step 112 is executed; otherwise, reporting an error to the upper computer through the current protocol channel; returning to the step 102;
specifically, the device determines whether a binding identifier corresponding to a protocol identifier corresponding to a device protocol type corresponding to the current protocol channel is set, and if so, determines that the device protocol type corresponding to the current protocol channel is bound to the communication application, and performs step 112; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 102;
after the step 111 is judged as no, before reporting an error to the upper computer through the current protocol channel, the method further comprises the following steps: judging whether the management application is selected or not, if so, obtaining a communication instruction from the USB communication instruction, and sending the communication instruction to the selected management application; receiving a communication response returned by the application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step 102; otherwise, reporting error to the upper computer through the current protocol channel, and returning to the step 102.
Step 112: the equipment obtains a communication instruction according to the USB communication instruction, and sends the communication instruction to a communication application bound with the equipment protocol type corresponding to the current protocol channel; and receiving a communication response returned by the application.
Specifically, the device takes effective data in the USB communication instruction as a communication instruction, and sends the communication instruction to a communication application bound with a device protocol type corresponding to the current protocol channel; and receiving a communication response returned by the application.
After the step 111 is judged to be yes and before the step 112, the method further comprises the following steps:
step c 1: the method comprises the steps that the equipment obtains an application identifier of a communication application bound with an equipment protocol type corresponding to a current protocol channel, and organizes and selects an application instruction according to the application identifier;
step c 2: the equipment sends the application selection instruction to the application corresponding to the application identifier in the application selection instruction; receiving a select application response;
step c 3: the device judges whether the selected application is successful according to the selected application response, if so, the step 112 is executed; otherwise, an error is reported to the upper computer, and the step 102 is returned.
In this embodiment, each communication is applied as follows;
step a 1: the communication application waits for receiving the instruction from the equipment, analyzes the instruction to judge the type of the instruction after receiving the instruction from the equipment, and executes the step a2 after receiving the communication instruction from the equipment; after receiving the application selection instruction from the device, returning to an application selection response, and returning to the step a 1;
step a 2: the communication application judges whether the user key information needs to be acquired according to the communication instruction, if so, the step a3 is executed; otherwise, organizing the communication response, returning the communication response comprising the first return code to the equipment, and returning to the step a 1;
for example: the communication application judges that the user key information does not need to be acquired according to the version reading instruction '000300000000000000', organizes the version reading application 5532465F 5629000 comprising the first return code '9000', returns the communication response comprising the first return code to the equipment, and returns to the step a 1;
for example: the communication application judges that the user key information needs to BE acquired according to the authentication command '000203000000813726F 4E76A7C657B37B806DD84BB8319FC1088365722290FDCAC825E24729A1A0102030405060708090A0B0C0D0E 100102030405060708090A0B0C0D0E 1040FBF261F599616DE16606033381BA762451E5B0F48B44C58DAF9439A10FA2AC2513D08A46F269E98FA386481659B4BC5EE8DF8EE5A499B2CAA44BE23EE 88440000', and then executes step A3 224;
step a 3: the communication application judges whether the user presses the key, if so, the step a4 is executed; otherwise, returning the communication response including the error code to the equipment, and returning to the step a 1;
specifically, the communication application detects whether the key IO is low, if yes, determines whether the user has pressed the key, and if yes, performs step a 4; otherwise, judging that the user does not press a key, returning the communication response including the error code to the equipment, and returning to the step a 1;
for example: if the communication application detects that the key IO is not low, it determines that the user has not pressed the key, and returns a communication response 6985 including an error code 69885 to the device, and returns to step a 1.
Step a 4: the communication application organizes the communication response according to the key information of the user, returns the communication response to the equipment and returns to the step a 1.
For example, after detecting that the user key information is the confirmation information, the communication application organizes the communication response including the first return code 9000, returns the communication response to the device, and returns to step a 1.
In this embodiment, the management application waits for an instruction from the device, analyzes the instruction to determine the type of the instruction after receiving the instruction from the device, returns an application selection response after receiving the application selection instruction, and continues to wait for receiving the instruction from the device; when the received instruction from the equipment is a communication instruction for installing the application, installing a plurality of communication applications, and returning an installation response to the equipment as a communication response; continue to wait for receipt of instructions from the device.
For example: when the command received by the management application from the equipment is a communication command for installing the application, installing the first communication application, the second communication application and the third communication application, and returning an installation response to the equipment as a communication response; continue to wait for receipt of instructions from the device.
Step 113: the device packages the communication response according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response, and returns the USB communication response to the upper computer through the current protocol channel, and the step 102 is returned.
If the current protocol channel is an HID protocol channel, the steps are specifically as follows: packaging the communication response according to the HID protocol type to obtain a USB communication response comprising an HID protocol head and the communication response;
for example: the communication response 6985 is encapsulated according to the HID protocol type to the USB communication response 00000001830002698500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 comprising the HID protocol header 00000001830002 and the communication response 69885, wherein the data 02 in the last byte of the HID protocol header is the data length of the communication response, i.e. the data length of the communication response is 2 bytes.
If the current protocol channel is a CCID protocol channel, the method specifically comprises the following steps: packaging the communication response according to the CCID protocol type to obtain a USB communication response comprising a CCID protocol head and the communication response;
for example: the communication response 6985 is packaged according to the CCID protocol type to the USB communication response 800200000000400000006985 comprising a CCID protocol header 80020000000040000000 and a communication response 69885, wherein the data 02 on the second byte in the CCID protocol header is the data length of the communication response, i.e. the data length of the communication response is 2 bytes.
If the current protocol channel is an SCSI protocol channel, the step specifically includes: encapsulating the communication response according to the SCSI protocol type to obtain a communication response and a USB communication response responding to the control word;
for example: the communication reply 6985 is encapsulated according to the SCSI protocol type to a USB communication reply 69855553425358444 e8a 0000000000 comprising the communication reply 69885 and the response control word 5553425358444 e8a 0000000000.
Step 114: the device obtains an application identifier from the USB selection application command, determines whether the application corresponding to the application identifier is bound to the device protocol type corresponding to the current device protocol channel, and if so, performs step 115; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 101;
specifically, the device selects the data length of the application identifier from the valid data of the application instruction from the USB, obtains the application identifier from the data field of the valid data according to the data length of the application identifier, determines whether the application corresponding to the application identifier is bound with the current device protocol type corresponding to the current device protocol channel, and if so, executes step 115; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 102;
the method comprises the following specific steps: after the device obtains the application identifier from the USB selection application command, if the application corresponding to the application identifier is a management application, step 115 is executed; if the application corresponding to the application identifier is a communication application, checking whether a binding identifier corresponding to the protocol identifier is set, if so, judging that the device protocol type corresponding to the protocol identifier is a bound communication application, and executing step 115; otherwise, judging that the equipment protocol type corresponding to the protocol identifier is not bound to the communication application, reporting an error to the upper computer through the current protocol channel, and returning to the step 102.
For example: the device obtains the data length 08 of the application identifier from the valid data 00a 4040008 a 000000151051000000 of the USB selection application instruction 0000000183000 d 00a 4040008 a 000000151000000 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc, obtains the data "a 000000151000000" with the data length of 8 bytes from the data field "a 000000151000000" of the valid data according to the data length of the application identifier, and takes the data as the application identifier "a 000000151000000", and if the application identifier is determined to be the identifier corresponding to the management application, step 115 is executed;
step 115: the device obtains a selection application instruction according to the USB selection application instruction, and sends the selection application instruction to an application corresponding to an application identifier in the selection application instruction; receiving a select application response;
specifically, the device takes effective data in the USB selection application instruction as a selection application instruction, and sends the selection application instruction to an application corresponding to an application identifier in the selection application instruction; receiving a select application response;
before step 115, the device further determines whether an application corresponding to the application identifier in the application selection instruction exists, and if so, executes step 115; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 102;
step 116: the equipment organizes the selective application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selective application response, returns the USB selective application response to the upper computer through the current protocol channel, and returns to the step 102.
In this embodiment, step 107 may also be replaced by: the equipment sets the own equipment protocol type according to the equipment protocol type bound with the communication application, and returns to the step 102; step 110 may also be replaced with: the device resets the binding identifier corresponding to the protocol identifier, returns to the upper computer that the unbinding is successful, sets the device protocol type of the device according to the default device protocol type and the device protocol type of the bound communication application, and returns to the step 102.
Correspondingly, after the device performs the operation of setting the device protocol type of the device according to the device protocol type of the bound communication application in step 107, or performs the operation of setting the device protocol type of the device according to the default device protocol type and the device protocol type of the bound communication application in step 110, if the device is inserted into the upper computer again, the device performs step 101.
In this embodiment, after the device is reset or re-inserted into the upper computer, the upper computer detects that a voltage difference exists between D + and D-, and the upper computer considers that the device is inserted.
Or when the device sets the device protocol type of the device in step 107 according to the device protocol type of the bound communication application, and after returning to step 102; the upper computer receives the successful binding response, resets the equipment and executes the step 101; when the device resets the binding identifier corresponding to the protocol identifier in step 110, returns successful unbinding to the upper computer, sets the device protocol type of the upper computer according to the default device protocol type and the device protocol type of the bound communication application, returns to step 102, the upper computer receives a successful unbinding response, the upper computer resets the device, and the device executes step 101.
Wherein, host computer reset equipment specifically is: the upper computer sends a reset command to the equipment through the concentrator of the upper computer, and the equipment resets after receiving the reset command.
In this embodiment, if the command is a USB selection application command, the step 114 may further include: the device determines whether the device protocol type corresponding to the current protocol channel matches the default device protocol type, if yes, step 117 is executed; otherwise, go to step 114; after the step 109 is judged as no, the method also comprises the following steps before the error is reported to the upper computer: judging whether the equipment protocol type corresponding to the current protocol channel is matched with the default equipment protocol type, if so, obtaining a communication instruction from the USB communication instruction, and sending the communication instruction to the currently selected application; receiving a communication response returned by the application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step 102; otherwise, reporting error to the upper computer through the current protocol channel, and returning to the step 102.
Step 117: the equipment acquires an application identifier and an application selection instruction from the USB application selection instruction, and sends the application selection instruction to the communication application corresponding to the application identifier in the USB application selection instruction; receiving a select application response; packaging the selective application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selective application response, returning the USB selective application response to the upper computer, and returning to the step 102;
the embodiment provides a method for dynamically matching the protocol type and the application of the multi-protocol USB equipment, the USB equipment provided by the method supports multiple equipment protocol types and multiple applications, each protocol and each application can be dynamically matched, the applicability of the equipment is enhanced, and the user experience is good.
Example 2
The embodiment provides a method for dynamically matching a protocol type of a multi-protocol USB device with an application, as shown in fig. 2, the method includes:
step 201: the equipment reports the own equipment protocol type to the upper computer;
specifically, the device acquires the device protocol type according to the device protocol type parameter of the device, and reports the device protocol type of the device to the upper computer according to the acquired device protocol type.
The initial value of the equipment protocol type parameter is matched with all equipment protocol types supported by the equipment, and when the equipment is inserted into the computer for the first time, the equipment reports all the supported equipment protocol types to the upper computer.
In this embodiment, the device is specifically a USB device, and all device protocol types supported by the device are multiple (more than two). For example, all the device protocol types supported by the device reporting device to the upper computer are an HID protocol type, a CCID protocol type and a SCSI protocol type, respectively.
Step 202: the equipment waits for receiving an instruction from the upper computer, judges the type of the instruction after receiving the instruction from the upper computer through the current protocol channel, and executes the step 203 if the type of the instruction is a protocol switching instruction; if the command type is a USB communication command, go to step 206; if the command type is a USB selection application command, go to step 208;
in this embodiment, the device waits for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type, and when receiving the instruction, the channel receiving the instruction of the upper computer is used as the current protocol channel.
In this embodiment, the type of the judgment instruction is specifically: and judging the type of the instruction received through the current protocol channel according to the effective data of the instruction, wherein the effective data in the instruction is an Application Protocol Data Unit (APDU) in the instruction.
Specifically, the device waits for receiving an instruction from the upper computer, after receiving the instruction from the upper computer through the current protocol channel, the device analyzes the instruction according to the device protocol type corresponding to the current protocol channel to obtain effective data in the instruction, and if data on the first three bytes of the effective data is a first preset character string, the instruction is a protocol switching instruction, and step 203 is executed; if the first three bytes of the valid data are the third preset character string, the command is a USB selection application command, and step 208 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 206 is executed.
In this embodiment, the first preset character string may be: 80E 100; the third predetermined string may be 00a 404.
More specifically: the method comprises the steps that the equipment waits for receiving an instruction from an upper computer, when the instruction from the upper computer is received through a current protocol channel, the instruction is analyzed according to the equipment protocol type corresponding to the current protocol channel, data on a first preset position in the instruction are obtained and are required to be used as effective data length, data with the data length being the effective data length are obtained from data on a second preset position in the instruction, the obtained data are used as effective data, and if the data on the first three bytes of the effective data are first preset character strings, the instruction is a protocol switching instruction, and step 203 is executed; if the first three bytes of the valid data are the third preset character string, the command is a USB selection application command, and step 208 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 206 is executed.
In this embodiment, if the current protocol channel is an HID protocol channel corresponding to the HID protocol, the first preset position may be, but is not limited to, a seventh byte in the instruction, and the second preset position may be, but is not limited to, an eighth byte in the instruction; if the current protocol channel is a CCID protocol channel corresponding to the CCID protocol, the first preset location may be, but is not limited to, a second byte in the instruction, and the second preset location may be, but is not limited to, an eleventh byte in the instruction; if the current protocol channel is a SCSI protocol channel corresponding to a SCSI protocol, the first predetermined location may be, but is not limited to, a ninth byte in the instruction, and the second predetermined location may be, but is not limited to, a thirty-second byte in the instruction.
For example: the device waits for receiving an instruction from the upper computer, when the instruction 0000000183000580E 1000100 cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc from the upper computer is received through the HID protocol channel, the data "05" on the seventh byte in the instruction is acquired and is taken as the effective data length according to the HID protocol analysis instruction corresponding to the HID protocol channel, the data with the effective data length is acquired from the data on the eighth byte in the instruction, the acquired data 80E 1000100 is taken as the effective data, the data on the first three bytes of the effective data is the first preset character string 80E100, and then the instruction is a protocol switching instruction, step 203 is performed.
Another example is: the device waits for receiving an instruction from the upper computer, when the instruction 6f 05000000003E 00000080E 1000000 from the upper computer is received through the CCID protocol channel, the instruction is analyzed according to the CCID protocol corresponding to the CCID protocol channel, data "05" on the second byte in the instruction is acquired and is used as an effective data length, data with the data length being the effective data length is acquired from data on the eleventh byte in the instruction, the acquired data 80E1000000 is used as effective data, and the instruction is a protocol switching instruction if the data on the first three bytes of the effective data is the first preset character string 80E100, then step 203 is executed.
For example, when the device waits for receiving an instruction from the upper computer, and receives an instruction 55534243 c 80945870500000000000 a ff 45504153530000005500000000000080E 1000000 from the upper computer through the SCSI protocol channel, the device parses the instruction according to the SCSI protocol corresponding to the SCSI protocol channel, acquires data "05" in the ninth byte in the instruction and requests the data to be used as an effective data length, acquires data with the effective data length from the data in the thirty second byte in the instruction, and uses the acquired data 80E1000000 as effective data, and if the data in the first three bytes of the effective data is the first preset character string 80E100, the instruction is a protocol switching instruction, step 203 is executed.
It should be further noted that, if the current protocol channel is an SCSI protocol channel corresponding to an SCSI protocol, after receiving an instruction from the upper computer through the current protocol channel, analyzing the instruction according to the device protocol type corresponding to the current protocol channel, and determining whether the type of the instruction is an instruction for the upper computer to send data to the device, if so, acquiring data at a first preset position in the instruction and please use the data as an effective data length, starting to acquire data with the effective data length from the last data at a second preset position in the instruction, and using the acquired data as effective data, otherwise, executing a corresponding operation.
Step 203: the equipment sets the protocol type of the equipment according to the protocol identification in the protocol switching instruction;
in this embodiment, the device sets its own device protocol type according to the protocol identifier in the protocol switching instruction; specifically, the device updates the device type parameter according to the protocol identifier in the protocol switching instruction.
Specifically, the device acquires data on a fourth section in valid data in a protocol switching instruction, and uses the data as a protocol identifier; and setting the own device protocol type as the device protocol type corresponding to the protocol identification.
In this embodiment, 00 is a protocol identifier corresponding to the HID protocol; 01 is a protocol identification corresponding to the CCID protocol; 02 is the protocol identification corresponding to the SCSI protocol.
For example: the device acquires the data 01 on the fourth section in the valid data 80e 1000100 in the protocol switching instruction 0000000183000580 e 1000100 cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc and takes the data as the protocol identifier; and setting the self device protocol type as the CCID protocol type corresponding to the protocol identifier 01.
Step 204: the equipment organizes a protocol switching response according to the equipment protocol type corresponding to the current protocol channel and returns the protocol switching response to the upper computer through the current protocol channel;
if the current protocol channel is an HID protocol channel, the steps are specifically as follows: organizing a protocol switching response comprising an HID protocol header and valid response data according to the HID protocol type; returning a protocol switching response to the upper computer through the current protocol channel;
for example: organizing a protocol switch acknowledgement 000000018300029000 including an HID protocol header 00000001830002 and valid acknowledgement data 9000 according to an HID protocol type; returning a protocol switching response to the upper computer through the current protocol channel; wherein, the data 02 on the last byte in the HID protocol header is the data length of the valid response data, that is, the data length of the valid response data is 2 bytes.
If the current protocol channel is a CCID protocol channel, the method specifically comprises the following steps: organizing a protocol switching response comprising a CCID protocol header and effective response data according to the CCID protocol type; returning a protocol switching response to the upper computer through the current protocol channel;
for example: organizing a protocol switch acknowledgement 800200000000400000009000 including a CCID protocol header 80020000000040000000 and valid acknowledgement data 9000 according to a CCID protocol type; returning a protocol switching response to the upper computer through the current protocol channel; wherein, the data 02 on the second byte in the CCID protocol header is the data length of the valid response data, that is, the data length of the valid response data is 2 bytes.
If the current protocol channel is an SCSI protocol channel, the step specifically includes: encapsulating and organizing a protocol switching response comprising effective response data and a response control word according to the SCSI protocol type; returning a protocol switching response to the upper computer through the current protocol channel;
for example: encapsulating a protocol switch acknowledgement 90005553425358444 e8a 0000000000 organized to include valid acknowledgement data 9000 and a response control word 5553425358444 e8a 0000000000 according to a SCSI protocol type; and returning a protocol switching response to the upper computer through the current protocol channel.
Step 205: resetting the equipment and returning to the step 201;
in this embodiment, after step 204, step 202 may also be directly returned to;
correspondingly, when the upper computer receives the protocol switching response, the upper computer resets the device, and the device executes step 201. Or after the device executes step 204, if the device is inserted into the upper computer again, the device executes step 201.
Step 206: the equipment obtains a communication instruction according to the USB communication instruction and sends the communication instruction to the currently selected application; and receiving a communication response returned by the application.
Specifically, the device takes effective data in the USB communication instruction as a communication instruction, and sends the communication instruction to the currently selected application; and receiving a communication response returned by the application.
In this embodiment, the application includes a management application and a communication application. The device is pre-installed with a management application, and each device protocol type supported by the device can be accessed, managed and utilized. The device can install the communication application through the management application.
In this embodiment, the management application waits for an instruction from the device, analyzes the instruction to determine the type of the instruction after receiving the instruction from the device, returns an application selection response after receiving the application selection instruction, and continues to wait for receiving the instruction from the device; when the received instruction from the equipment is a communication instruction for installing the application, installing a plurality of communication applications, and returning an installation response to the equipment as a communication response; continue to wait for receipt of instructions from the device.
For example: when the command received by the management application from the equipment is a communication command for application installation, installing a first communication application, a second communication application and a third communication application, and returning an installation response to the equipment; and continuing to wait for receiving a communication command from the equipment.
In this embodiment, each communication application executes the following operations;
step a 1: the communication application waits for receiving the instruction from the equipment, analyzes the instruction to judge the type of the instruction after receiving the instruction from the equipment, and executes the step a2 after receiving the communication instruction from the equipment; after receiving the application selection instruction from the device, returning to an application selection response, and returning to the step a 1;
step a 2: the communication application judges whether the user key information needs to be acquired according to the communication instruction, if so, the step a3 is executed; otherwise, organizing the communication response, returning the communication response comprising the first return code to the equipment, and returning to the step a 1;
for example: the communication application judges that the user key information does not need to be acquired according to the version reading instruction '000300000000000000', organizes the version reading application 5532465F 5629000 comprising the first return code '9000', returns the communication response comprising the first return code to the equipment, and returns to the step a 1;
for example: the communication application judges that the user key information needs to BE acquired according to the authentication command '000203000000813726F 4E76A7C657B37B806DD84BB8319FC1088365722290FDCAC825E24729A1A0102030405060708090A0B0C0D0E 100102030405060708090A0B0C0D0E 1040FBF261F599616DE16606033381BA762451E5B0F48B44C58DAF9439A10FA2AC2513D08A46F269E98FA386481659B4BC5EE8DF8EE5A499B2CAA44BE23EE 88440000', and then executes step A3 224;
step a 3: the communication application judges whether the user presses the key, if so, the step a4 is executed; otherwise, returning the communication response including the error code to the equipment, and returning to the step a 1;
specifically, the communication application detects whether the key IO is low, if yes, determines whether the user has pressed the key, and if yes, performs step a 4; otherwise, judging that the user does not press a key, returning the communication response including the error code to the equipment, and returning to the step a 1;
for example: if the communication application detects that the key IO is not low, it determines that the user has not pressed the key, and returns a communication response 6985 including an error code 69885 to the device, and returns to step a 1.
Step a 4: the communication application organizes the communication response according to the key information of the user, returns the communication response to the equipment and returns to the step a 1.
For example, after detecting that the user key information is the confirmation information, the communication application organizes the communication response including the first return code 9000, returns the communication response to the device, and returns to step a 1.
Step 207: the device packages the communication response according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response, returns the USB communication response to the upper computer through the current protocol channel, and returns to step 202.
If the current protocol channel is an HID protocol channel, the steps are specifically as follows: packaging the communication response according to the HID protocol type to obtain a USB communication response comprising an HID protocol head and the communication response;
for example: the communication response 6985 is encapsulated according to the HID protocol type to the USB communication response 00000001830002698500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 comprising the HID protocol header 00000001830002 and the communication response 69885, wherein the data 02 in the last byte of the HID protocol header is the data length of the communication response, i.e. the data length of the communication response is 2 bytes.
If the current protocol channel is a CCID protocol channel, the method specifically comprises the following steps: packaging the communication response according to the CCID protocol type to obtain a USB communication response comprising a CCID protocol head and the communication response;
for example: the communication response 6985 is packaged according to the CCID protocol type to the USB communication response 800200000000400000006985 comprising a CCID protocol header 80020000000040000000 and a communication response 69885, wherein the data 02 on the second byte in the CCID protocol header is the data length of the communication response, i.e. the data length of the communication response is 2 bytes.
If the current protocol channel is an SCSI protocol channel, the step specifically includes: encapsulating the communication response according to the SCSI protocol type to obtain a communication response and a USB communication response responding to the control word;
for example: the communication reply 6985 is encapsulated according to the SCSI protocol type to a USB communication reply 69855553425358444 e8a 0000000000 comprising the communication reply 69885 and the response control word 5553425358444 e8a 0000000000.
Step 208: the device obtains a selection application instruction according to the USB selection application instruction, and sends the selection application instruction to an application corresponding to an application identifier in the selection application instruction; receiving a select application response;
specifically, the device takes effective data in the USB selection application instruction as a selection application instruction, acquires the data length of the application identifier from the selection application instruction, acquires the application identifier from the data field in the selection application instruction according to the data length of the application identifier, and sends the selection application instruction to the application corresponding to the application identifier in the selection application instruction; receiving a select application response;
step 209: the device organizes the selective application response according to the device protocol type corresponding to the current protocol channel to obtain a USB selective application response, returns the USB selective application response to the upper computer through the current protocol channel, and returns to the step 202.
Example 3
The embodiment provides a method for dynamically matching a protocol type of a multi-protocol USB device with an application, as shown in fig. 3, the method includes:
in this embodiment, the device is specifically a USB device, and the device includes a first chip and a second chip;
preferably, the first chip is a USB chip; the second chip is a JAVA card chip.
Step 300: the first chip reports the self equipment protocol type to the upper computer;
in this embodiment, the first chip reports to the upper computer that the device protocol type of the first chip is one or more (more than two) of the USB protocol types supported by the first chip.
Specifically, the first chip acquires the first chip protocol type according to the first chip protocol type parameter of the first chip, and reports the first chip protocol type of the first chip to the upper computer according to the acquired first chip protocol type.
The initial value of the first chip protocol type parameter is matched with the default first chip protocol type, the default first chip protocol type can be one or more, and when the first chip is inserted into the computer for the first time, the first chip reports the default first chip protocol type to the upper computer.
For example: when the equipment is inserted into the computer for the first time, the first chip reports the default equipment protocol type to the upper computer as the HID protocol type; or when the equipment is inserted into the computer for the first time, the first chip reports the default equipment protocol type to the upper computer as the HID protocol type and the CCID protocol type.
Step 301: the first chip waits for receiving an instruction from the upper computer, judges the type of the instruction after receiving the instruction from the upper computer through the current protocol channel, and executes the step 302 if the instruction is a binding protocol instruction; if the instruction is an unbind protocol instruction, go to step 308; if the command is a USB communication command, go to step 311; if the command is a USB application selection command, go to step 316;
in this embodiment, the first chip waits for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type, and when the instruction is received, the channel receiving the instruction of the upper computer is used as the current protocol channel.
The type of the judgment instruction is specifically as follows: judging the type of the instruction received through the current protocol channel according to the valid data of the instruction, wherein the valid data in the instruction is an Application Protocol Data Unit (APDU) in the instruction.
Specifically, the first chip waits for receiving an instruction from the upper computer, after receiving the instruction from the upper computer through the current protocol channel, the first chip obtains effective data in the instruction according to a device protocol type analysis instruction corresponding to the current protocol channel, and if data on the first three bytes of the effective data is a first preset character string, the instruction is a binding protocol instruction, and step 302 is executed; if the data in the first three bytes of the valid data is the second preset character string, the instruction is a unbinding protocol instruction, and then step 308 is executed; if the first three bytes of the valid data are the third preset character string, the command is a USB selection application command, and step 316 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 311 is executed.
In this embodiment, the first preset character string may be: 80E 100; the second predetermined character may be: 80E 101; the third predetermined string may be 00a 404.
More specifically: the first chip waits for receiving an instruction from the upper computer, when the instruction from the upper computer is received through the current protocol channel, the instruction is analyzed according to the device protocol type corresponding to the current protocol channel, data on a first preset position in the instruction are obtained and are required to be used as effective data length, data with the data length being the effective data length are obtained from data on a second preset position in the instruction, the obtained data are used as effective data, and if the data on the first three bytes of the effective data are first preset character strings, the instruction is a binding protocol instruction, and step 302 is executed; if the data in the first three bytes of the valid data is the second preset character string, the instruction is a unbinding protocol instruction, and then step 308 is executed; if the first three bytes of the valid data are the third preset character string, the command is a USB selection application command, and step 316 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 311 is executed.
In this embodiment, if the current protocol channel is an HID protocol channel corresponding to the HID protocol, the first preset position may be, but is not limited to, a seventh byte in the instruction, and the second preset position may be, but is not limited to, an eighth byte in the instruction; if the current protocol channel is a CCID protocol channel corresponding to the CCID protocol, the first preset location may be, but is not limited to, a second byte in the instruction, and the second preset location may be, but is not limited to, an eleventh byte in the instruction; if the current protocol channel is a SCSI protocol channel corresponding to a SCSI protocol, the first predetermined location may be, but is not limited to, a ninth byte in the instruction, and the second predetermined location may be, but is not limited to, a thirty-second byte in the instruction.
For example: the first chip waits for receiving the instruction from the upper computer, when receiving the instruction 0000000183000 d 80e 1000008 a 0000006472 f 0001 cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc from the upper computer through the HID protocol channel, according to the HID protocol parsing instruction corresponding to the HID protocol channel, data "0 d" in the seventh byte in the instruction is acquired and is used as the valid data length, data with the data length being the valid data length is acquired from the data in the eighth byte in the instruction, the acquired data 80E 1000008 a 0000006472 f 0001 is used as the valid data, and if the data in the first three bytes of the valid data is the first preset character string 80E100, the instruction is the binding protocol instruction, then step 302 is executed.
Another example is: the first chip waits for receiving an instruction from the upper computer, when the instruction 6f 0d 000000003E 00000080E 1010008 a 0000006472 f 0001 from the upper computer is received through the CCID protocol channel, the data "0 d" on the second byte in the instruction is acquired and is used as the effective data length according to the CCID protocol parsing instruction corresponding to the CCID protocol channel, the data with the data length being the effective data length is acquired from the data on the eleventh byte in the instruction, the acquired data 80E 1010008 a 0000006472 f 0001 is used as the effective data, and the instruction is the unbinding protocol instruction if the data on the first three bytes of the effective data is the second preset character string 80E 101, then step 308 is executed.
For example, the first chip waits to receive an instruction from the upper computer, and when the instruction 55534243 c 80945870 d 00000000000 a ff 45504153530000005500000000000000 a 4040008 a 0000006472 f 0001 from the upper computer is received through the SCSI protocol channel, acquires data "0 d" in the ninth byte in the instruction and requests to be used as an effective data length according to the SCSI protocol analysis instruction corresponding to the SCSI protocol channel, starts to acquire data with the effective data length from data in the thirty-second byte in the instruction, and uses the acquired data 00a 4040008 a 0000006472 f 0001 as effective data, and if the data in the first three bytes of the effective data is the third preset character string 00a 404, the instruction is the USB selection application instruction, then step 316 is executed.
It should be further noted that, if the current protocol channel is an SCSI protocol channel corresponding to an SCSI protocol, after receiving an instruction from the upper computer through the current protocol channel, analyzing the instruction according to the device protocol type corresponding to the current protocol channel, and determining whether the type of the instruction is an instruction for the upper computer to send data to the first chip, if so, acquiring data at a first preset position in the instruction and please use the data as an effective data length, starting to acquire data with the effective data length from data at a second preset position in the instruction, and using the acquired data as effective data, otherwise, executing a corresponding operation.
Step 302: the first chip acquires a protocol identifier and an application identifier from the binding protocol instruction;
specifically, the first chip acquires data on a fourth section in valid data of the binding protocol instruction, and uses the data as a protocol identifier; and taking the data on the fifth byte in the effective data of the binding protocol instruction as the data length of the application identifier, and acquiring the application identifier from the data field of the effective data of the binding protocol instruction according to the data length of the application identifier.
For example: the first chip acquires the data 00 on the fourth section in the valid data 80E 1000008A 0000006472F 0001 of the binding protocol instruction and takes the data 00 as a protocol identifier; taking the data 08 on the fifth byte in the valid data of the binding protocol instruction as the data length of the application identifier, and acquiring the data "A0000006472F 0001" with the data length of 8 bytes from the data field A000000006472F 0001 of the valid data of the binding protocol instruction as the application identifier.
In this embodiment, 00 is a protocol identifier corresponding to the HID protocol; 01 is a protocol identification corresponding to the CCID protocol; 02 is the protocol identification corresponding to the SCSI protocol.
Step 303: the first chip judges whether the equipment protocol type corresponding to the protocol identification is bound with the communication application, if so, the first chip reports an error to the upper computer through the current protocol channel and returns to the step 301; otherwise, go to step 304;
specifically, the first chip checks whether a binding identifier corresponding to the protocol identifier is set, if so, judges that the device protocol type corresponding to the protocol identifier is bound to the communication application, reports an error to the upper computer through the current protocol channel, and returns to step 301; otherwise, it is determined that the device protocol type corresponding to the protocol identifier is not bound to the communication application, and step 304 is executed.
In this embodiment, a management application and a plurality of communication applications are installed in the device, and each device protocol type supported by the device can be accessed, managed and utilized. The device can install each communication application through the management application, the management application is an application for managing each communication application, and each communication application is an application for realizing the functionality of the device: such as OTP applications, PKI applications, FIDO applications.
Step 304: the first chip organizes a selection application instruction comprising an application identifier, and sends the selection application instruction to the second chip through an I2C/7816 interface;
specifically, the first chip takes the application identifier as data in a data domain of the application instruction, adds an instruction header of the application instruction before the data domain to obtain the application instruction including the application identifier, and sends the application instruction to the second chip through the I2C/7816 interface.
For example: the first chip takes the application identifier 'A0000006472F 0001' as data in a data domain of the selected application instruction, adds an instruction header '00A 4040008' of the selected application instruction before the data domain to obtain the selected application instruction '00A 4040008A 0000006472F 0001' comprising the application identifier, and sends the selected application instruction to the second chip through an I2C/7816 interface.
Step 305: the second chip acquires an application identifier from the application selection instruction and judges whether an application corresponding to the application identifier exists or not; if so, sending the application selection instruction to the application corresponding to the application identifier, receiving an application selection response, returning the application selection response to the first chip through the I2C/7816 interface, and executing step 306; otherwise, reporting an error to the first chip, reporting an error to the upper computer by the first chip, and returning to the step 301;
step 306: the first chip judges whether the selected application is successful or not according to the selected application response, if so, sets a binding identifier corresponding to the protocol identifier, organizes the binding success response according to the device protocol type corresponding to the current protocol channel, returns the binding success response to the upper computer through the current protocol channel, and executes step 307; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 301;
the successful binding response is organized according to the device protocol type corresponding to the current protocol channel, and specifically comprises the following steps: and organizing and reporting the binding success response of the first success identification according to the equipment protocol type corresponding to the current protocol channel.
For example: the binding success acknowledgement 00000001830002900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 of the first successful identification 9000 is reported according to the HID protocol type organization corresponding to the HID protocol tunnel.
In this step, after setting the binding identifier corresponding to the protocol identifier, the method further includes: and correspondingly storing the application identifier and the protocol identifier in the binding protocol instruction.
Step 307: the first chip sets the own device protocol type according to the device protocol type bound with the communication application, resets the first chip and returns to the step 300;
specifically, the first chip updates the device type parameter of the first chip according to the device protocol type of the bound communication application; the first chip is reset and the process returns to step 300.
Step 307 may specifically be: the first chip sets the own device protocol type according to the device protocol type of the currently bound communication application, resets the first chip and returns to the step 300;
for example: the first chip sets the device protocol type of the first chip as the HID protocol type of the first communication application which is currently bound and corresponds to the application identifier 'A0000006472F 0001', resets the first chip and returns to the step 300;
step 307 may further specifically be: the first chip sets the own device protocol type according to all the device protocol types bound with the communication application, resets the first chip and returns to the step 300;
for example: the first chip sets the device protocol type of itself to the HID protocol type bound with the first communication application and the CCID protocol type bound with the second communication application, resets the first chip, and returns to step 300.
In this embodiment, step 307 may be replaced by step b 1: the first chip judges whether the device protocol type of the currently bound communication application is matched with the currently reported device protocol type, if so, the step 301 is returned to; otherwise, the device protocol type of the first chip is set according to the device protocol type of the bound communication application, the first chip is reset, and the step 300 is returned. The step b1 is specifically as follows: the first chip judges whether the device protocol type of the currently bound communication application is one of the currently reported device protocol types, if so, the device protocol type of the currently bound communication application is judged to be matched with the currently reported device protocol type, and the step 301 is returned to; otherwise, judging that the device protocol type of the currently bound communication application is not matched with the device protocol type reported currently, setting the device protocol type of the currently bound communication application as the device protocol type of all the device protocol types of the bound communication application, resetting the first chip, and returning to the step 300.
For example: if the first chip determines that the HID protocol type of the currently bound first communication application is one of the currently reported device protocol types (CCID protocol type and HID protocol type), the first chip determines that the device protocol type of the currently bound first communication application is matched with the currently reported device protocol type, and then the process returns to step 301.
Step b1 may also be specifically: the first chip judges whether the equipment protocol type of the currently bound communication application is completely consistent with the equipment protocol type reported currently, if so, the equipment protocol type of the currently bound communication application is judged to be matched with the equipment protocol type reported, and the step 301 is returned to; otherwise, judging that the device protocol type of the currently bound communication application is not matched with the device protocol type reported currently, setting the device protocol type of the currently bound communication application as the device protocol type of all the device protocol types of the bound communication application, resetting the first chip, and returning to the step 300.
For example: the first chip judges that the HID protocol type bound with the first communication application is not completely consistent with the current reported device protocol type (the HID protocol type and the CCID protocol type), judges that the device protocol type bound with the first communication application is not matched with the current reported device protocol type, sets the device protocol type of the first chip as the HID protocol type bound with the device protocol type of the first communication application, resets the first chip, and returns to the step 300.
In this embodiment, the first chip in step b1 sets the device protocol type of its own according to the device protocol type of the bound communication application, specifically: the first chip sets the own device protocol type according to the device protocol type of the current bound communication application or sets the own device protocol type according to the device protocol types of all the bound communication applications.
Step 308: the first chip acquires a protocol identifier and an application identifier from the unbinding protocol instruction;
specifically, the first chip acquires data on a fourth section in effective data of the unbinding protocol instruction, and uses the data as a protocol identifier; and taking the data on the fifth byte in the effective data as the data length of the application identifier, and acquiring the application identifier from the data field of the effective data of the unbinding protocol instruction according to the data length of the application identifier.
For example: the first chip acquires data "00" on the fourth section in the valid data "80E 1010008" in the unbinding protocol command "80E 1010008 a 0000006472F 0001", and takes it as a protocol identifier; taking data "08" on the fifth byte of the valid data as the data length of the application identifier, and acquiring data "a 0000006472F 0001" with the data length of 8 bytes from the data field of the valid data as the application identifier.
Step 309: the first chip judges whether the device protocol type corresponding to the protocol identification is bound with the communication application, if so, the step 310 is executed; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 301;
specifically, the first chip checks whether a binding identifier corresponding to the protocol identifier is set, and if so, determines that the device protocol type corresponding to the protocol identifier is bound to the communication application, and then executes step 310; otherwise, judging that the device protocol type corresponding to the protocol identifier is not bound with the communication application, reporting an error to the upper computer through the current protocol channel, and returning to the step 301.
Step 310: the first chip resets the binding identifier corresponding to the protocol identifier, returns a successful unbinding response to the upper computer through the current protocol channel, sets the own equipment protocol type according to the default equipment protocol type and the equipment protocol type of the bound communication application, resets the first chip, and returns to the step 300.
In this step, the specific device protocol type setting according to the default device protocol type and the device protocol type bound with the communication application is as follows: the equipment judges whether the equipment protocol type of the bound communication application exists or not, and if so, the equipment protocol type of the equipment is set according to the equipment protocol type of the bound communication application; otherwise, setting the own device protocol type as the default device protocol type.
In this step, the device protocol type of the device is set according to the device protocol type of the bound communication application, specifically: and setting the own device protocol type as one or more of the device protocol types of the bound communication application.
In this step, after resetting the binding identifier corresponding to the protocol identifier, the method further includes: and deleting the application identifier stored corresponding to the protocol identifier.
Step 311: the first chip judges whether the device protocol type corresponding to the current protocol channel is bound with the communication application, if so, the step 312 is executed; otherwise, reporting an error to the upper computer through the current protocol channel; returning to the step 301;
specifically, the first chip determines whether a binding identifier corresponding to a protocol identifier corresponding to a device protocol type corresponding to the current protocol channel is set, and if so, determines that the device protocol type corresponding to the current protocol channel is bound to the communication application, and performs step 312; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 301;
after the step 311 is judged as no, before reporting an error to the upper computer, the method further includes: judging whether the management application is selected or not, if so, obtaining a communication instruction from the USB communication instruction, and sending the communication instruction to the selected management application; receiving a communication response returned by the application; packaging the communication response according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step 301; otherwise, an error is reported to the upper computer through the current protocol channel, and the step 301 is returned to.
Step 312: the first chip obtains a communication instruction according to the USB communication instruction, and sends the communication instruction to the second chip through the I2C/7816 interface;
specifically, the first chip takes effective data in the USB communication instruction as a communication instruction, and sends the communication instruction to the second chip through an I2C/7816 interface;
after the step 311 is determined to be yes and before the step 312, the method further includes:
step c 1: the first chip acquires an application identifier of a communication application bound with a device protocol type corresponding to a current protocol channel, and organizes and selects an application instruction according to the application identifier;
step c 2: the first chip sends the application selection instruction to the second chip through an I2C/7816 interface;
step c 3: the second chip sends the application selection instruction to the application corresponding to the application identifier in the application selection instruction; receiving a select application response;
step c 4: the second chip sends the application selection response to the first chip through an I2C/7816 interface;
step c 5: the first chip judges whether the application selection is successful according to the application selection response, and if so, step 312 is executed; otherwise, an error is reported to the upper computer, and the step 301 is returned to.
Step 313: the second chip sends the communication instruction to the communication application bound with the equipment protocol type corresponding to the current protocol channel; and receiving a communication response returned by the application.
In this embodiment, the second chip is pre-installed with a management application, and each device protocol type supported by the device can be accessed, managed and utilized. The second chip can install the communication application on the second chip through the management application.
In this embodiment, the management application waits for receiving an instruction, analyzes the instruction to determine the type of the instruction after receiving the instruction from the first chip, returns an application selection response to the first chip through the second chip after receiving the application selection instruction, and continues to wait for receiving the instruction; when the received command is a communication command, installing a plurality of communication applications according to the communication command, and returning an installation response serving as a communication response to the first chip through the second chip; continue to wait for instructions to be received.
For example: when the command received by the management application is a communication command for installing the communication application, installing the first communication application, the second communication application and the third communication application, and returning an installation response serving as a communication response to the first chip through the second chip; continue to wait for instructions to be received.
In this embodiment, the communication application performs the operations shown in fig. 4;
step a 1: the communication application waits for receiving the instruction, analyzes the instruction to judge the type of the instruction after receiving the instruction from the first chip, and executes the step a2 after receiving the communication instruction; after receiving the application selection instruction, returning an application selection response to the first chip through the second chip, and returning to the step a 1;
step a 2: the communication application judges whether the user key information needs to be acquired according to the communication instruction, if so, the step a3 is executed; otherwise, organizing the communication response, returning the communication response to the first chip through the second chip, and returning to the step a 1;
for example: the communication application judges that the user key information does not need to be acquired according to the version reading instruction of 000300000000000000, organizes a communication response 5532465F 5629000 comprising a first return code of 9000, returns the communication response comprising the first return code to the first chip through the second chip, and returns to the step a 1;
another example is: the communication application judges that the user key information needs to BE acquired according to the authentication command '000203000000813726F 4E76A7C657B37B806DD84BB8319FC1088365722290FDCAC825E24729A1A0102030405060708090A0B0C0D0E 100102030405060708090A0B0C0D0E 1040FBF261F599616DE16606033381BA762451E5B0F48B44C58DAF9439A10FA2AC2513D08A46F269E98FA386481659B4BC5EE8DF8EE5A499B2CAA44BE23EE 88440000', and then executes step A3 224;
step a 3: setting the key IO pin of the second chip as input by the communication application, detecting whether the level of the key IO pin of the second chip is low, and if so, executing the step a 4; otherwise, returning the communication response including the second return code to the first chip through the second chip, and returning to the step a 1;
in this embodiment, the second return code may be 6FF 1.
Step a 4: and the communication application sets the key IO pin of the second chip as output, controls the second chip to output low level to the key IO pin of the first chip, organizes the communication response comprising the first return code, returns the communication response comprising the first return code to the first chip through the second chip, and returns to the step a 1.
Step 314: the second chip returns a communication response to the first chip through the I2C/7816 interface;
step 315: the first chip obtains a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returns the USB communication response to the upper computer through the current protocol channel, and returns to the step 301.
As shown in fig. 5, the present step specifically includes:
step 3511: the first chip judges the type of the received communication response, and if the communication response is the communication response comprising the first return code, the step 3512 is executed; if the communication response includes the second return code, execute step 3515;
step 3512: the first chip detects whether the key detection identifier is set, and if so, the step 3513 is executed; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step 301;
step 3513: the first chip sets a key IO pin of the first chip as input;
step 3514: the first chip judges whether the level of the key IO pin of the first chip is low, if so, resets the key detection identifier, closes the first timer, closes the key detection process, obtains a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returns the USB communication response to the upper computer through the current protocol channel, raises the level of the key IO pin of the first chip, and returns to the step 301; otherwise, return to step 3514;
step 3515: the first chip judges whether the key detection mark is set, if so, a USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel, the USB communication response is returned to the upper computer through the current protocol channel, and the step 301 is returned; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step 301; setting a key detection identifier, starting a first timer, and starting a key detection process; waiting for obtaining user key information within a first preset time specified by a first timer, and outputting a low level to a key IO pin of a second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
Step 316: the first chip obtains an application identifier from the USB selection application instruction, judges whether an application corresponding to the application identifier is bound with a current device protocol type corresponding to a current device protocol channel, and executes step 317 if the application corresponding to the application identifier is bound with the current device protocol type corresponding to the current device protocol channel; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 301;
specifically, the first chip obtains the data length of the application identifier from the valid data of the USB selection application instruction, obtains the application identifier from the data field of the selection application instruction according to the data length of the application identifier, and if the application corresponding to the application identifier is the management application, performs step 317; if the application corresponding to the application identifier is a communication application, determining whether the communication application corresponding to the application identifier is bound with the current device protocol type corresponding to the current device protocol channel, if so, executing step 317; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step 301;
for example: the first chip obtains the data length 08 of the application identifier from the valid data 00a 4040008 a 000000151051000000 of the USB selection application instruction 0000000183000 d 00a 4040008 a 000000151000000 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc, obtains the application identifier "a 000000151000000" from the data field "a 000000151000000" of the selection application instruction according to the data length of the application identifier, judges that the application identifier is an identifier corresponding to the management application, and executes step 317;
step 317: the first chip obtains an application selection instruction from the USB application selection instruction, and sends the application selection instruction to the second chip through an I2C/7816 interface;
step 318: the second chip sends the application selection instruction to the application corresponding to the application identifier in the application selection instruction; receiving a select application response;
before step 318, the second chip determines whether an application corresponding to the application identifier in the application selection instruction exists, and if so, step 318 is executed; otherwise, reporting an error to the first chip, reporting an error to the upper computer by the first chip, and returning to the step 301;
step 319: the second chip sends the application selection response to the first chip through an I2C/7816 interface;
step 320: the first chip packages the communication response according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response, and returns the USB communication response to the upper computer through the current protocol channel, and the step 301 is returned.
In this embodiment, step 307 may be replaced by: the first chip sets the own device protocol type according to the device protocol type bound with the communication application, and returns to the step 301; step 310 may also be replaced with: the first chip resets the binding identifier corresponding to the protocol identifier, returns success of unbinding to the upper computer, sets the own device protocol type according to the default device protocol type and the device protocol type of the bound communication application, and returns to the step 301.
Accordingly, after the first chip performs the operation of setting the device protocol type of the first chip according to the device protocol type of the bound communication application in step 307, or performs the operation of setting the device protocol type of the first chip according to the default device protocol type and the device protocol type of the bound communication application in step 310, if the device is inserted into the upper computer again, the first chip performs step 300.
Or when the first chip sets the own device protocol type according to the device protocol type of the bound communication application in step 307, returning to step 301; the upper computer receives the successful binding response, resets the first chip, and executes the step 300; when the first chip resets the binding identifier corresponding to the protocol identifier in step 310, returns successful unbinding to the upper computer, sets the own device protocol type according to the default device protocol type and the device protocol type of the bound communication application, returns to step 301, the upper computer receives a successful unbinding response, the upper computer resets the first chip, and the first chip executes step 300.
In this embodiment, if the command is a USB selection application command, the step 316 may further include: the first chip judges whether the device protocol type corresponding to the current protocol channel is matched with the default device protocol type, if so, step 321 is executed; otherwise, go to step 316; after the step 311 is judged as no, the method further comprises the following steps before the error is reported to the upper computer: judging whether the equipment protocol type corresponding to the current protocol channel is matched with the default equipment protocol type, if so, obtaining a communication instruction from the USB communication instruction, and sending the communication instruction to the currently selected application; receiving a communication response returned by the application; packaging the communication response according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step 301; otherwise, an error is reported to the upper computer through the current protocol channel, and the step 301 is returned to.
Step 321: the first chip acquires an application identifier and an application selection instruction from the USB application selection instruction, and sends the application selection instruction to the communication application corresponding to the application identifier in the USB application selection instruction; receiving a select application response; packaging the selective application response according to the device protocol type corresponding to the current protocol channel to obtain a USB selective application response, returning the USB selective application response to the upper computer, and returning to the step 301;
the embodiment provides a method for dynamically matching the protocol type and the application of the multi-protocol USB equipment, the USB equipment provided by the method supports multiple equipment protocol types and multiple applications, each protocol and each application can be dynamically matched, the applicability of the equipment is enhanced, and the user experience is good.
Example 4
The embodiment provides a method for dynamically matching a protocol type of a multi-protocol USB device with an application, as shown in fig. 6, the method includes:
step 401: the first chip reports the equipment protocol type of the equipment to the upper computer;
specifically, the first chip acquires the device protocol type according to the device protocol type parameter of the first chip, and reports the device protocol type of the device to the upper computer according to the acquired device protocol type.
The initial value of the equipment protocol type parameter is matched with all equipment protocol types supported by the equipment, and when the equipment is inserted into the computer for the first time, the first chip reports all the equipment protocol types supported by the equipment to the upper computer.
In this embodiment, the device is specifically a USB device, and all device protocol types supported by the device are multiple (more than two). For example, all the device protocol types supported by the first chip reporting device to the upper computer are an HID protocol type, a CCID protocol type and a SCSI protocol type, respectively.
Step 402: the first chip waits for receiving an instruction from the upper computer, judges the type of the instruction after receiving the instruction from the upper computer through the current protocol channel, and executes step 403 if the instruction is a protocol switching instruction; if the command is a USB communication command, go to step 406; if the command is a USB application selection command, go to step 410;
in this embodiment, the first chip waits for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type, and when the instruction is received, the channel receiving the instruction of the upper computer is used as the current protocol channel.
In this embodiment, the type of the judgment instruction is specifically: judging the type of the instruction received through the current protocol channel according to the valid data of the instruction, wherein the valid data in the instruction is an Application Protocol Data Unit (APDU) in the instruction.
Specifically, the first chip waits for receiving an instruction from the upper computer, after receiving the instruction from the upper computer through the current protocol channel, the first chip obtains effective data in the instruction according to a device protocol type analysis instruction corresponding to the current protocol channel, and if data on the first three bytes of the effective data is a first preset character string, the instruction is a protocol switching instruction, and then step 403 is executed; if the first three bytes of the valid data are the third predetermined character string, the command is a USB selection application command, and then step 410 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 406 is executed.
In this embodiment, the first preset character string may be: 80E 100; the third predetermined string may be 00a 404.
More specifically: the first chip waits for receiving an instruction from the upper computer, when the instruction from the upper computer is received through the current protocol channel, the instruction is analyzed according to the device protocol type corresponding to the current protocol channel, data on a first preset position in the instruction are obtained and are required to be used as effective data length, data with the data length being the effective data length are obtained from data on a second preset position in the instruction, the obtained data are used as effective data, and if the data on the first three bytes of the effective data are first preset character strings, the instruction is a protocol switching instruction, and then step 403 is executed; if the first three bytes of the valid data are the third predetermined character string, the command is a USB selection application command, and then step 410 is executed; if the data in the first three bytes of the command is other character strings, the command is a USB communication command, and step 406 is executed.
In this embodiment, if the current protocol channel is an HID protocol channel corresponding to the HID protocol, the first preset position may be, but is not limited to, a seventh byte in the instruction, and the second preset position may be, but is not limited to, an eighth byte in the instruction; if the current protocol channel is a CCID protocol channel corresponding to the CCID protocol, the first preset location may be, but is not limited to, a second byte in the instruction, and the second preset location may be, but is not limited to, an eleventh byte in the instruction; if the current protocol channel is a SCSI protocol channel corresponding to a SCSI protocol, the first predetermined location may be, but is not limited to, a ninth byte in the instruction, and the second predetermined location may be, but is not limited to, a thirty-second byte in the instruction.
For example: the first chip waits for receiving an instruction from the upper computer, when the instruction 0000000183000580E 1000100 cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc from the upper computer is received through the HID protocol channel, the data "05" on the seventh byte in the instruction is acquired and is taken as the effective data length according to the HID protocol analysis instruction corresponding to the HID protocol channel, the data with the data length being the effective data length is acquired from the data on the eighth byte in the instruction, the acquired data 80E 1000100 is taken as the effective data, the data on the first three bytes of the effective data is the first preset character string 80E100, and then the instruction is the protocol switching instruction, step 403 is performed.
Another example is: the first chip waits for receiving an instruction from the upper computer, and when the instruction 6f 05000000003E 00000080E 1000000 from the upper computer is received through the CCID protocol channel, the instruction is analyzed according to the CCID protocol corresponding to the CCID protocol channel, data "05" in the second byte in the instruction is obtained and is used as an effective data length, data with the data length being the effective data length is obtained from the data in the eleventh byte in the instruction, the obtained data 80E1000000 is used as effective data, and the instruction is a protocol switching instruction if the data in the first three bytes of the effective data is the first preset character string 80E100, then step 403 is executed.
For example, the first chip waits to receive a command from the upper computer, when receiving a command 55534243 c 80945870500000000000 a ff 45504153530000005500000000000080E 1000000 from the upper computer through the SCSI protocol channel, according to the SCSI protocol analysis command corresponding to the SCSI protocol channel, obtains data "05" in the ninth byte in the command and please use the data as an effective data length, obtains data with a data length of the effective data length from data in the thirty second byte in the command, uses the obtained data 80E1000000 as effective data, and if the data in the first three bytes of the effective data is the first preset character string 00a 404, the command is the first preset character string 80E100, and the command is a protocol switching command, step 403 is executed.
It should be further noted that, if the current protocol channel is an SCSI protocol channel corresponding to an SCSI protocol, after receiving an instruction from the upper computer through the current protocol channel, analyzing the instruction according to the device protocol type corresponding to the current protocol channel, and determining whether the type of the instruction is an instruction for the upper computer to send data to the device, if so, acquiring data at a first preset position in the instruction and please use the data as an effective data length, starting to acquire data with the effective data length from the last data at a second preset position in the instruction, and using the acquired data as effective data, otherwise, executing a corresponding operation.
Step 403: the first chip sets the own equipment protocol type according to the protocol identification in the protocol switching instruction;
in this embodiment, the first chip sets its own device protocol type according to the protocol identifier in the protocol switching instruction; specifically, the first chip updates the device type parameter according to the protocol identifier in the protocol switching instruction.
Specifically, the first chip acquires data on a fourth section in valid data in a protocol switching instruction, and uses the data as a protocol identifier; and setting the own device protocol type as the device protocol type corresponding to the protocol identification.
In this embodiment, 00 is a protocol identifier corresponding to the HID protocol; 01 is a protocol identification corresponding to the CCID protocol; 02 is the protocol identification corresponding to the SCSI protocol.
For example: the first chip acquires the data 01 on the fourth section in the valid data 80e 1000100 in the protocol switching instruction 0000000183000580 e 1000100 cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cccc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc and takes the data as the protocol identifier; and setting the self device protocol type as the CCID protocol type corresponding to the protocol identifier 01.
Step 404: the first chip organizes a protocol switching response according to the equipment protocol type corresponding to the current protocol channel and returns the protocol switching response to the upper computer through the current protocol channel;
if the current protocol channel is an HID protocol channel, the steps are specifically as follows: organizing a protocol switching response comprising an HID protocol header and valid response data according to the HID protocol type; returning a protocol switching response to the upper computer through the current protocol channel;
for example: organizing a protocol switch acknowledgement 000000018300029000 including an HID protocol header 00000001830002 and valid acknowledgement data 9000 according to an HID protocol type; returning a protocol switching response to the upper computer through the current protocol channel; wherein, the data 02 on the last byte in the HID protocol header is the data length of the valid response data, that is, the data length of the valid response data is 2 bytes.
If the current protocol channel is a CCID protocol channel, the method specifically comprises the following steps: organizing a protocol switching response comprising a CCID protocol header and effective response data according to the CCID protocol type; returning a protocol switching response to the upper computer through the current protocol channel;
for example: organizing a protocol switch acknowledgement 800200000000400000009000 including a CCID protocol header 80020000000040000000 and valid acknowledgement data 9000 according to a CCID protocol type; returning a protocol switching response to the upper computer through the current protocol channel; wherein, the data 02 on the second byte in the CCID protocol header is the data length of the valid response data, that is, the data length of the valid response data is 2 bytes.
If the current protocol channel is an SCSI protocol channel, the step specifically includes: encapsulating and organizing a protocol switching response comprising effective response data and a response control word according to the SCSI protocol type; returning a protocol switching response to the upper computer through the current protocol channel;
for example: encapsulating a protocol switch acknowledgement 90005553425358444 e8a 0000000000 organized to include valid acknowledgement data 9000 and a response control word 5553425358444 e8a 0000000000 according to a SCSI protocol type; and returning a protocol switching response to the upper computer through the current protocol channel.
Step 405: resetting the first chip and returning to the step 401;
in this embodiment, after step 404, it may also directly return to step 402;
correspondingly, when the upper computer receives the protocol switching response, the upper computer resets the device, and the device executes step 401. Or after the device executes step 404, if the device is inserted into the upper computer again, the device executes step 401.
Step 406: the first chip obtains a communication instruction according to the USB communication instruction, and sends the communication instruction to the second chip through the I2C/7816 interface;
specifically, the first chip takes effective data in the USB communication instruction as a communication instruction, and sends the communication instruction to the second chip through an I2C/7816 interface;
step 407: the second chip sends the communication instruction to the currently selected application to acquire a communication response returned by the application;
in this embodiment, the second chip is pre-installed with a management application, and each device protocol type supported by the device can be accessed, managed and utilized. The second chip can install the communication application through the management application.
In this embodiment, the management application waits for receiving an instruction from the second chip, analyzes the instruction to determine the type of the instruction after receiving the instruction from the device, returns an application selection response after receiving an application selection instruction from the second chip, and continues to wait for receiving the instruction; when the received instruction is a communication instruction for application installation, installing a plurality of communication applications, and returning an installation response to the second chip as a communication response; continue to wait for instructions to be received.
For example: when the command received by the management application is a communication command for application installation, installing a first communication application, a second communication application and a third communication application, and returning an installation response to the second chip as a communication response; continue to wait for instructions to be received.
In this embodiment, the communication application performs the operations shown in fig. 4.
Step 408: the second chip returns the communication response to the first chip through the I2C/7816 interface;
step 409: the first chip obtains a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returns the USB communication response to the upper computer through the current protocol channel, and returns to the step 402.
Step 409 specifically includes:
step 4091: the first chip judges the type of the received communication response, if the communication response comprises the first return code, the step 4092 is executed; if the communication response includes the second return code, executing step 4094;
step 4092: the first chip detects whether the key detection identification is set, if so, step 4093 is executed; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step 402;
step 4093: the first chip sets a key IO pin of the first chip as input;
step 4094: the first chip judges whether the level of the IO pin of the key of the first chip is low, if so, resets the key detection identifier, closes the first timer, closes the key detection process, obtains a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returns the USB communication response to the upper computer through the current protocol channel, and returns to the step 402; otherwise, returning to step 4094;
step 4095: the first chip judges whether the key detection mark is set, if so, a USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel, the USB communication response is returned to the upper computer through the current protocol channel, and the step 402 is returned; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, returning to the step 402, starting a first timer, setting a key detection identifier, waiting for obtaining user key information within a first preset time, and outputting a low level to a key IO pin of the second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
Step 410: the first chip obtains an application selection instruction according to the USB application selection instruction, and sends the application selection instruction to the second chip through the I2C/7816 interface;
step 411: the second chip sends the application selection instruction to the application corresponding to the application identifier in the application selection instruction; receiving a select application response;
step 412: the second chip sends the application selection response to the first chip through an I2C/7816 interface;
step 413: the first chip organizes the selective application response according to the device protocol type corresponding to the current protocol channel to obtain a USB selective application response, returns the USB selective application response to the upper computer, and returns to the step 402.
Example 5
The embodiment provides a multi-protocol USB device with a device protocol type dynamically matched with an application, as shown in fig. 7; the method comprises the following steps:
in this embodiment, the application is installed on the device; the application comprises the following steps: communication application;
the device comprises a reporting protocol type module 01, a first receiving module 02, a first judging module 03, a first obtaining module 04, a first selecting application module 05, a first binding module 06, a first returning module 07, a first setting module 08, a second obtaining module 09, a first unbinding module 10, a second setting module 11, a third obtaining module 12, a first sending module 13, a second receiving module 14 and a first packaging module 15;
the report protocol type module 01 is used for reporting one or more equipment protocol types of the equipment to the upper computer after the equipment is inserted into the upper computer;
the first receiving module 02 is used for waiting to receive the instruction from the upper computer through a channel corresponding to the reported device protocol type;
the first judging module 03 is configured to judge the type of the instruction received through the current protocol channel after the first receiving module 02 receives the instruction from the upper computer through the current protocol channel;
the first obtaining module 04 is configured to obtain a protocol identifier and an application identifier from a binding protocol instruction when the first determining module 03 determines that the instruction received through the current protocol channel is the binding protocol instruction;
the first selection application module 05 is configured to select a communication application corresponding to the application identifier acquired by the first acquisition module 04;
the first binding module 06 is configured to bind, after the first selection application module 05 selects the communication application corresponding to the application identifier acquired by the first acquisition module 04, the device protocol type corresponding to the protocol identifier acquired by the first acquisition module 04 and the communication application corresponding to the application identifier acquired by the first acquisition module 04;
the first returning module 07 is used for returning a binding success response to the upper computer through the current protocol channel; returning a successful unbinding response to the upper computer through the current protocol channel; the USB communication response obtained by the first packaging module 15 is returned to the upper computer through the current protocol channel;
the first setting module 08 is configured to set the device protocol type of the device according to the device protocol type of the bound communication application after the first binding module 06 binds the device protocol type corresponding to the protocol identifier acquired by the first acquiring module 04 with the communication application corresponding to the application identifier acquired by the first acquiring module 04;
the second obtaining module 09 is configured to obtain the protocol identifier and the application identifier from the unbinding protocol instruction when the first determining module 03 determines that the instruction received through the current protocol channel is the unbinding protocol instruction;
the first unbinding module 10 is configured to unbind the device protocol type corresponding to the protocol identifier acquired by the second acquiring module 09 and the communication application corresponding to the application identifier acquired by the second acquiring module 09;
the second setting module 11 is configured to set the device protocol type of the device according to the default device protocol type and the device protocol type of the bound communication application, after the first unbinding module 10 unbinds the device protocol type corresponding to the protocol identifier acquired by the second acquiring module 09 and the communication application corresponding to the application identifier acquired by the second acquiring module 09;
the third obtaining module 12 is configured to obtain a communication instruction from the USB communication instruction when the first determining module 03 determines that the instruction received through the current protocol channel is the USB communication instruction;
the first sending module 13 is configured to send the communication instruction obtained by the third obtaining module 12 to the communication application bound to the device protocol type corresponding to the current protocol channel;
the second receiving module 14 is configured to receive a communication response returned by the communication application bound to the device protocol type corresponding to the current protocol channel;
the first encapsulating module 15 is configured to encapsulate the communication response received by the second receiving module 14 according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response.
In this embodiment, the apparatus may further include: a reset module;
the resetting module is used for resetting the equipment after the first setting module 08 sets the equipment protocol type of the equipment according to the equipment protocol type of the bound communication application; when the second setting module 11 sets the device protocol type of the device according to the default device protocol type and the device protocol type bound with the communication application, resetting the device;
and the report protocol type module 01 is also used for reporting the equipment protocol type of the equipment to the upper computer after the reset module resets the equipment.
In this embodiment, the apparatus may further include: the second judgment module and the first error reporting module;
the second judging module is configured to judge whether the device protocol type corresponding to the current protocol channel is bound with a communication application after the first judging module 03 judges that the instruction received through the current protocol channel is a USB communication instruction;
the third obtaining module 12 is specifically configured to obtain a communication instruction from the USB communication instruction after the second determining module determines that the communication instruction is received;
and the first error reporting module is used for reporting errors to the upper computer through the current protocol channel after the second judging module judges that the second judging module is not the first judging module.
In this embodiment, the apparatus may further include: the device comprises a fourth acquisition module, a third judgment module, a second error reporting module, a fifth acquisition module, a second sending module, a third receiving module and a second packaging module;
the fourth obtaining module is configured to obtain the application identifier from the USB selection application instruction when the first determining module 03 determines that the instruction received through the current protocol channel is the USB selection application instruction;
the third judging module is used for judging whether the communication application corresponding to the application identifier acquired by the fourth acquiring module is bound with the equipment protocol type corresponding to the current equipment protocol channel;
the second error reporting module is used for reporting errors to the upper computer through the current protocol channel after the third judging module judges that the third judging module is negative;
the fifth obtaining module is used for obtaining an application selection instruction from the USB application selection instructions after the third judging module judges that the USB application selection instruction is positive;
the second sending module is used for sending the application selection instruction obtained by the fifth obtaining module to the communication application corresponding to the application identifier in the USB application selection instruction;
a third receiving module, configured to receive a response of selecting an application;
the second packaging module is used for packaging the selected application response received by the third receiving module according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selected application response;
the first returning module 07 is further configured to return the USB selection application response to the upper computer.
Further, in this embodiment, the applying may further include: managing the application; accordingly, the apparatus may further comprise: the device comprises a tenth judging module, an eleventh judging module, a fourth error reporting module, a tenth acquiring module, a twelfth judging module and an eleventh acquiring module;
the tenth judging module is configured to, after the first judging module 03 judges that the instruction received through the current protocol channel is the USB communication instruction, judge whether the device protocol type corresponding to the current protocol channel is bound to the communication application;
the third obtaining module 12 is specifically configured to obtain a communication instruction from the USB communication instruction after the tenth determining module determines that the communication instruction is yes;
an eleventh judging module, configured to judge whether the management application has been selected after the tenth judging module judges that the management application is not selected;
the tenth obtaining module is used for obtaining a communication instruction from the USB communication instruction and sending the communication instruction to the selected management application after the eleventh judging module judges that the USB communication instruction is positive; receiving a communication response returned by the management application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response;
the fourth error reporting module is used for reporting an error to the upper computer through the current protocol channel after the eleventh judging module judges that the error is not the case; a twelfth judging module, configured to judge the type of the application identifier obtained by the fourth obtaining module;
an eleventh obtaining module, configured to, when the twelfth determining module determines that the application identifier obtained by the fourth obtaining module is an application identifier corresponding to the management application, obtain a selected application instruction from the USB selected application instruction, and send the selected application instruction to the management application corresponding to the application identifier in the USB selected application instruction; receiving a select application response; packaging and selecting an application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selection application response;
the third judging module is specifically configured to, when the twelfth judging module judges that the application identifier acquired by the fourth acquiring module is the application identifier corresponding to the communication application, judge whether the communication application corresponding to the application identifier is already bound to the device protocol type corresponding to the current device protocol channel;
the first returning module 07 is further configured to return the USB selection application response acquired by the eleventh acquiring module to the upper computer through the current protocol channel; and returning the USB communication response acquired by the tenth acquisition module to the upper computer through the current protocol channel.
In this embodiment, the report protocol type module 01 is specifically configured to obtain the device protocol type according to the device type parameter of the module itself, and report one or more of the device protocol types of the module itself to the upper computer according to the obtained device protocol type;
the first setting module 08 is specifically configured to update the device type parameter of the first binding module 06 according to the device protocol type of the bound communication application after the first binding module 06 binds the device protocol type corresponding to the protocol identifier acquired by the first acquiring module 04 with the communication application corresponding to the application identifier acquired by the first acquiring module 04;
the second setting module 11 is specifically configured to update the device type parameter of the first unbinding module 10 according to the default device protocol type and the device protocol type of the bound communication application after the first unbinding module unbinding the device protocol type corresponding to the protocol identifier acquired by the second acquiring module 09 and the communication application corresponding to the application identifier acquired by the second acquiring module 09.
In this embodiment, the apparatus may further include: the device comprises a fourth judging module, a sixth acquiring module, a seventh acquiring module, a fifth judging module, a third error reporting module, an eighth acquiring module, a sixth judging module, a seventh judging module and a ninth acquiring module;
the fourth judging module is configured to, when the first judging module 03 judges that the instruction received through the current protocol channel is the USB selection application instruction, judge whether the device protocol type corresponding to the current protocol channel matches the default device protocol type;
the sixth obtaining module is used for obtaining the application identifier and the application selection instruction from the USB application selection instruction and sending the application selection instruction to the communication application corresponding to the application identifier in the USB application selection instruction after the fourth judging module judges that the application identifier and the application selection instruction are the same; receiving a select application response; packaging and selecting an application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selection application response;
the seventh obtaining module is used for obtaining the application identifier in the USB selection application instruction after the fourth judging module judges that the application identifier is not the application identifier;
the fifth judging module is used for judging whether the communication application corresponding to the application identifier acquired by the seventh acquiring module is bound with the device protocol type corresponding to the current device protocol channel;
the eighth obtaining module is used for obtaining an application selection instruction from the USB application selection instruction and sending the application selection instruction to the communication application corresponding to the application identifier in the USB application selection instruction after the fifth judging module judges that the application selection instruction is positive; receiving a select application response; packaging and selecting an application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selection application response;
the third error reporting module is used for reporting errors to the upper computer through the current protocol channel after the fifth judging module judges that the second protocol channel is not the first protocol channel; when the seventh judgment module judges that the protocol is not correct, an error is reported to the upper computer through the current protocol channel;
the sixth judging module is configured to, after the first judging module 03 judges that the instruction received through the current protocol channel is the USB communication instruction, judge whether the device protocol type corresponding to the current protocol channel is bound to the communication application;
the third obtaining module 12 is specifically configured to obtain a communication instruction from the USB communication instruction after the sixth determining module determines that the communication instruction is received;
the seventh judging module is used for judging whether the equipment protocol type corresponding to the current protocol channel is matched with the default equipment protocol type or not after the sixth judging module judges that the equipment protocol type is not matched with the default equipment protocol type;
the ninth obtaining module is used for obtaining a communication instruction from the USB communication instruction and sending the communication instruction to the currently selected application after the seventh judging module judges that the USB communication instruction is positive; receiving a communication response returned by the application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response;
the first returning module 07 is further configured to return the USB selective application response obtained by the sixth obtaining module, the USB selective application response obtained by the eighth obtaining module, and the USB communication response obtained by the ninth obtaining module to the upper computer through the current protocol channel.
In this embodiment, the first binding module 06 is specifically configured to set a binding identifier corresponding to the protocol identifier acquired by the first acquiring module 04; correspondingly storing the application identifier acquired by the first acquisition module 04 and the protocol identifier acquired by the first acquisition module 04;
the first unbinding module 10 is specifically configured to reset the binding identifier corresponding to the protocol identifier acquired by the second acquiring module 09; and deletes the application identifier stored corresponding to the protocol identifier acquired by the second acquisition module 09.
In this embodiment, the first selection application module 05 specifically includes: the device comprises a first organization unit, a first sending unit, a first receiving unit, a first judging unit and a first error reporting unit;
the first organizing unit is used for organizing a selection application instruction comprising the application identifier acquired by the first acquiring module 04;
the first sending unit is used for sending the application selection instruction organized by the first organization unit to the communication application corresponding to the application identifier acquired by the first acquisition module 04;
a first receiving unit configured to receive a selection application response;
the first judging unit is used for judging whether the selected application is successful according to the selected application response received by the first receiving unit;
the first binding module 06 is specifically configured to bind, after the first determining unit determines that the device identifier is the device identifier, the device protocol type corresponding to the protocol identifier acquired by the first acquiring module 04 with the communication application corresponding to the application identifier acquired by the first acquiring module 04;
and the first error reporting unit is used for reporting errors to the upper computer through the current protocol channel after the first judging unit judges that the first protocol channel is not the first protocol channel.
In this embodiment, the apparatus may further include: an eighth judging module;
an eighth determining module, configured to determine whether the device protocol type of the currently bound communication application matches the currently reported device protocol type after the first binding module 06 binds the device protocol type corresponding to the protocol identifier obtained by the first obtaining module 04 and the communication application corresponding to the application identifier obtained by the first obtaining module 04;
the first setting module 08 is specifically configured to, after the eighth determining module determines that the device protocol type of the device is not the binding communication application, set the device protocol type of the device according to the device protocol type of the binding communication application.
In this embodiment, the first setting module 08 is specifically configured to: after the first binding module 06 binds the device protocol type corresponding to the protocol identifier acquired by the first acquiring module 04 with the communication application corresponding to the application identifier acquired by the first acquiring module 04, the device protocol type of the device is set according to the device protocol type of the currently bound communication application or the device protocol type of the device is set according to the device protocol types of all the bound communication applications.
In this embodiment, the second setting module 11 specifically includes: a second judging unit and a first setting unit;
a second determining unit, configured to determine whether a device protocol type of a bound communication application exists after the first unbinding module 10 unbinds the device protocol type corresponding to the protocol identifier acquired by the second acquiring module 09 and the communication application corresponding to the application identifier acquired by the second acquiring module 09;
the first setting unit is used for setting the own equipment protocol type according to the equipment protocol type bound with the communication application after the second judging unit judges that the equipment protocol type is the equipment protocol type bound with the communication application; and when the second judgment unit judges that the equipment protocol type of the second judgment unit is not the default equipment protocol type, setting the equipment protocol type of the second judgment unit as the default equipment protocol type.
Further, the first setting unit is specifically configured to set the own device protocol type as one or more of the device protocol types of the bound communication applications after the second determining unit determines that the device protocol type is the true type; and when the second judgment unit judges that the equipment protocol type of the second judgment unit is not the default equipment protocol type, setting the equipment protocol type of the second judgment unit as the default equipment protocol type.
In this embodiment, the apparatus may further include: a thirteenth judging module, a fourteenth judging module and a fifth error reporting module;
a thirteenth judging module, configured to, after the first obtaining module 04 obtains the protocol identifier and the application identifier from the binding protocol instruction, judge whether the device protocol type corresponding to the protocol identifier obtained by the first obtaining module 04 is bound with the communication application;
the first selection application module 05 is specifically configured to select, after the thirteenth determining module determines that the communication application corresponds to the application identifier acquired by the first acquiring module 04;
a fourteenth determining module, configured to determine whether the device protocol type corresponding to the protocol identifier acquired by the second acquiring module 09 is bound with the communication application after the second acquiring module 09 acquires the protocol identifier and the application identifier from the unbinding protocol instruction;
the first unbinding module 10 is specifically configured to, after the fourteenth determining module determines that the protocol identifier is the device identifier, unbind the device protocol type corresponding to the protocol identifier acquired by the second acquiring module 09 and the communication application corresponding to the application identifier acquired by the second acquiring module 09;
the fifth error reporting module is used for reporting an error to the upper computer through the current protocol channel after the thirteenth judging module judges that the protocol channel is positive; and when the fourteenth judging module judges that the protocol is not the protocol channel, reporting an error to the upper computer through the current protocol channel.
In this embodiment, the device may specifically include a first chip and a second chip; the communication application is installed on the second chip;
the first chip includes: the device comprises a reporting protocol type module 01, a first receiving module 02, a first judging module 03, a first obtaining module 04, a first selecting application module 05, a first binding module 06, a first returning module 07, a first setting module 08, a second obtaining module 09, a first unbinding module 10, a second setting module 11, a third obtaining module 12, a first sending module 13, a second receiving module 14 and a first packaging module 15;
the second chip includes: the system comprises a fourth receiving module, a fourteenth judging module, a fifteenth judging module, a first organizing module, a third sending module, a third setting module, a first detecting module, a fourth setting module and a first control module;
the fourth receiving module is used for receiving the instruction from the first chip;
a fourteenth determining module, configured to determine the type of the instruction received by the fourth receiving module;
a fifteenth judging module, configured to judge whether to acquire user key information according to the communication instruction after the fourteenth judging module judges that the type of the instruction is the communication instruction;
the first organizing module is used for organizing the communication response comprising the first return code after the fifteenth judging module judges that the communication response comprises the first return code; when the first detection module detects that the first return code is the first return code, organizing a communication response comprising the first return code;
the third sending module is used for returning the communication response organized by the first organizing module to the first chip; and when the first detection module detects that the first chip is not the second chip, the communication response including the second return code is returned to the first chip;
the third setting module is used for setting the key IO pin of the second chip as input after the fifteenth judging module judges that the key IO pin is positive; when the first detection module detects that the input/output (IO) pin of the second chip is output;
the first detection module is used for detecting whether the level of a key IO pin of the second chip is low or not;
the first control module is used for controlling the second chip to output a low level to a key IO pin of the first chip after the first detection module detects that the first chip is the power supply module;
the first encapsulation module 15 specifically includes: the device comprises a third judging unit, a first detecting unit, a first packaging unit, a second setting unit, a fourth judging unit, a first resetting unit, a first pulling-up unit, a second detecting unit and a key detecting unit;
the third judging unit is used for judging the type of the received communication response;
the first detection unit is used for detecting whether the key detection identifier is set or not when the third judgment unit judges that the type of the received communication response is the communication response comprising the first return code;
the first packaging unit is used for obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel after the first detection unit detects that the equipment protocol type and the communication response are not the same; when the fourth judging unit judges that the communication command is the communication response comprising the second return code, the USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel;
the second setting unit is used for setting the key IO pin of the first chip as input after the first detection unit detects that the first chip is input;
the fourth judging unit is used for judging whether the level of the key IO pin of the fourth judging unit is low or not after the second setting unit sets the key IO pin of the first chip as input; judging whether the level of the IO pin of the key is low or not when the IO pin of the key is judged to be not;
the first resetting unit is used for resetting the key detection identifier, closing the first timer and closing the key detection process after the fourth judging unit judges that the key detection identifier is the first key detection identifier;
the first pull-up unit is used for pulling up the level of the key IO pin of the first chip after the fourth judgment unit judges that the fourth judgment unit is positive;
the second detection unit is used for judging whether the key detection identifier is set or not when the third judgment unit judges that the type of the received communication response is the communication response comprising the second return code;
the key detection unit is used for setting the key detection identifier, starting the first timer and starting the key detection process after the second detection unit detects that the key detection identifier is not set; waiting for obtaining user key information within a first preset time specified by a first timer, and outputting a low level to a key IO pin of a second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
In this embodiment, a multi-protocol USB device with dynamically matched device protocol types and applications is provided, where the device provided by the method supports multiple device protocol types and multiple applications, and each protocol and application can be dynamically matched with each other, so that the applicability of the device is enhanced, and the user experience is good.
Example 6
The embodiment provides a multi-protocol USB device with a device protocol type dynamically matched with an application, as shown in fig. 8;
in this embodiment, the application is installed on the device; the application comprises the following steps: communication application; the apparatus comprises: a reporting protocol type module 21, a first receiving module 22, a first judging module 23, a first setting module 24, a first returning module 25, a first obtaining module 26 and a second obtaining module 27;
the reporting protocol type module 21 is used for reporting the equipment protocol type of the equipment to the upper computer after the equipment is inserted into the upper computer;
the first receiving module 22 is configured to receive an instruction from the upper computer through a channel corresponding to the reported device protocol type;
a first determining module 23, configured to, after the first receiving module 22 receives the instruction, use the channel that receives the instruction as a current protocol channel, and determine a type of the instruction received through the current protocol channel;
the first setting module 24 is configured to set a device protocol type of the first determining module 23 according to a protocol identifier in a protocol switching instruction when the first determining module 23 determines that the instruction received through the current protocol channel is the protocol switching instruction;
the first returning module 25 is used for organizing a protocol switching response according to the equipment protocol type corresponding to the current protocol channel and returning the protocol switching response to the upper computer through the current protocol channel; the USB communication response is returned to the upper computer through the current protocol channel; and returning the USB selection application response to the upper computer through the current protocol channel;
the first obtaining module 26 is configured to, when the first determining module 23 determines that the instruction received through the current protocol channel is a USB communication instruction, obtain a communication instruction from the USB communication instruction, and send the communication instruction to the currently selected application; receiving a communication response returned by the application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response;
a second obtaining module 27, configured to obtain a selected application instruction from the USB selected application instruction when the first determining module 23 determines that the instruction received through the current protocol channel is the USB selected application instruction, and send the selected application instruction to an application corresponding to an application identifier in the selected application instruction; receiving a select application response; and organizing the selected application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selected application response.
In this embodiment, the apparatus may further include: a reset module;
the reset module is used for resetting the equipment after the first return module 25 returns a protocol switching response to the upper computer through the current protocol channel;
the report protocol type module 21 is further configured to report the device protocol type of the device to the upper computer after the reset module resets the device.
In this embodiment, the reporting protocol type module 21 is specifically configured to obtain the device protocol type according to the device type parameter of the reporting protocol type module, and report the device protocol type of the reporting protocol to the upper computer according to the obtained device protocol type;
the first setting module 24 is specifically configured to update the device type parameter according to the protocol identifier in the protocol switching instruction when the first determining module 23 determines that the instruction is the protocol switching instruction.
In this embodiment, the device specifically includes a first chip and a second chip; the communication application is installed on the second chip;
the first chip includes: a reporting protocol type module 21, a first receiving module 22, a first judging module 23, a first setting module 24, a first returning module 25, a first obtaining module 26 and a second obtaining module 27;
the second chip includes: the device comprises a second receiving module, a second judging module, a third judging module, a first organizing module, a first sending module, a second setting module, a first detecting module, a third setting module and a first control module;
the second receiving module is used for receiving the instruction from the first chip;
the second judging module is used for judging the type of the instruction received by the second receiving module;
the third judging module is used for judging whether the key information of the user needs to be acquired according to the communication instruction after the second judging module judges that the type of the instruction is the communication instruction;
the first organizing module is used for organizing the communication response comprising the first return code after the third judging module judges that the communication response comprises the first return code; when the first detection module detects that the first return code is the first return code, organizing a communication response comprising the first return code;
the first sending module is used for returning the communication response organized by the first organizing module to the first chip; and when the first detection module detects that the first chip is not the second chip, the communication response including the second return code is returned to the first chip;
the second setting module is used for setting the key IO pin of the second chip as input after the third judging module judges that the second chip is yes; when the first detection module detects that the input/output (IO) pin of the second chip is output;
the first detection module is used for detecting whether the level of a key IO pin of the second chip is low or not;
the first control module is used for controlling the second chip to output a low level to a key IO pin of the first chip after the first detection module detects that the first chip is the power supply module;
the first obtaining module 26 specifically includes: the device comprises a first acquisition unit, a first sending unit, a first receiving unit and a first packaging unit;
the first obtaining unit obtains the communication instruction from the USB communication instruction when the first judging module 23 judges that the instruction is the USB communication instruction;
the first sending unit is used for sending the communication instruction to the currently selected application;
the first receiving unit is used for receiving a communication response returned by the currently selected application;
the first packaging unit specifically includes: the device comprises a first judgment subunit, a first detection subunit, a first packaging subunit, a first setting subunit, a second judgment subunit, a first resetting subunit, a first pull-up subunit, a second detection subunit and a key detection subunit;
the first judging subunit is used for judging the type of the received communication response;
the first detection subunit is used for detecting whether the key detection identifier is set or not when the first judgment subunit judges that the type of the received communication response is the communication response comprising the first return code;
the first packaging subunit is used for obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel after the first detection subunit detects that the equipment protocol type and the communication response are not the same; when the second judging subunit judges that the communication instruction is the communication response comprising the second return code, the USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel;
the first setting subunit is used for setting the key IO pin of the first chip as input after the first detection subunit detects that the input is positive;
the second judging subunit is used for judging whether the level of the key IO pin of the second chip is low or not after the first setting subunit sets the key IO pin of the first chip as input; judging whether the level of the IO pin of the key is low or not when the IO pin of the key is judged to be not;
the first resetting subunit is used for resetting the key detection identifier, closing the first timer and closing the key detection process after the second judging subunit judges that the first timer is in the first state;
the first pull-up subunit is used for pulling up the level of the key IO pin of the first chip after the second judgment subunit judges that the first chip is the first chip;
the second detection subunit is used for judging whether the key detection identifier is set or not when the first judgment subunit judges that the type of the received communication response is the communication response comprising the second return code;
the key detection subunit is used for setting the key detection identifier, starting the first timer and starting the key detection process after the second detection subunit detects that the key detection identifier is not set; waiting for obtaining user key information within a first preset time specified by a first timer, and outputting a low level to a key IO pin of a second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
In this embodiment, a multi-protocol USB device with dynamically matched device protocol types and applications is provided, where the device provided by the method supports multiple device protocol types and multiple applications, and each protocol and application can be dynamically matched with each other, so that the applicability of the device is enhanced, and the user experience is good.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (42)

1. A method for dynamically matching a multi-protocol USB device protocol type with an application, wherein the application is installed on the device; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the method comprises the following steps:
step s 1: the equipment reports one or more of the own equipment protocol types to the upper computer;
step s 2: the device waits for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type, after the instruction is received, the channel receiving the instruction is used as a current protocol channel, the type of the instruction received through the current protocol channel is judged, and if the instruction received through the current protocol channel is a binding protocol instruction, the step s3 is executed; if the instruction received through the current protocol channel is a unbinding protocol instruction, executing step s 6; if the command received through the current protocol channel is a USB communication command, execute step s 8;
step s 3: the device acquires a protocol identifier and an application identifier from the binding protocol instruction;
step s 4: the equipment selects a communication application corresponding to the application identifier;
step s 5: the equipment binds the equipment protocol type corresponding to the protocol identifier with the communication application corresponding to the application identifier, returns a binding success response to the upper computer through the current protocol channel, sets the equipment protocol type of the equipment according to the equipment protocol type of the bound communication application, and returns to the step s 2;
step s 6: the equipment acquires a protocol identifier and an application identifier from the unbinding protocol instruction;
step s 7: the equipment unbinds the equipment protocol type corresponding to the protocol identifier and the communication application corresponding to the application identifier, and returns an unbinding success response to the upper computer through the current protocol channel; setting the own device protocol type according to the default device protocol type and the device protocol type bound with the communication application, and returning to the step s 2;
step s 8: the equipment obtains a communication instruction from the USB communication instruction, and sends the communication instruction to a communication application bound with an equipment protocol type corresponding to the current protocol channel; receiving a communication response returned by the application; and packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step s 2.
2. The method according to claim 1, wherein after setting the own device protocol type, before returning to step s2, the method further comprises:
the device is reset and the device performs step s 1.
3. The method of claim 1, further comprising:
when the upper computer receives the binding success response, the upper computer resets the equipment, and the equipment executes the step s 1;
and when the upper computer receives the unbinding success response, resetting the equipment by the upper computer, and executing the step s1 by the equipment.
4. The method of claim 1, further comprising: after the device sets its own device protocol type, if the device is inserted into the upper computer again, the device executes step s 1.
5. The method as claimed in claim 1, wherein after the step s2 determining that the command received via the current protocol channel is a USB communication command, the step s8 is executed before further comprising: judging whether the device protocol type corresponding to the current protocol channel is bound with the communication application, if so, executing the step s 8; otherwise, an error is reported to the upper computer through the current protocol channel, and the step s2 is returned.
6. The method according to claim 1, wherein the step s2 further comprises: if the instruction received through the current protocol channel is a USB application selection instruction, executing step s 9;
step s 9: the device obtains an application identifier from the USB selection application instruction, determines whether the communication application corresponding to the application identifier is bound to the device protocol type corresponding to the current device protocol channel, and if so, executes step s 10; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step s 2;
step s 10: the equipment obtains a selection application instruction from the USB selection application instruction, and sends the selection application instruction to the communication application corresponding to the application identifier in the USB selection application instruction; receiving a select application response; and packaging the selective application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selective application response, returning the USB selective application response to the upper computer, and returning to the step s 2.
7. The method according to claim 1, wherein said step s1 specifically comprises: the equipment acquires the equipment protocol type according to the equipment type parameter of the equipment, and reports one or more of the equipment protocol types of the equipment to the upper computer according to the acquired equipment protocol type;
the setting of the own device protocol type according to the device protocol type of the bound communication application specifically includes: updating the self equipment type parameter according to the equipment protocol type of the bound communication application;
the setting of the own device protocol type according to the default device protocol type and the device protocol type of the bound communication application specifically includes: and updating the own equipment type parameters according to the default equipment protocol type and the equipment protocol type of the bound communication application.
8. The method according to claim 1, wherein the step s2 further comprises: if the instruction received through the current protocol channel is a USB selection application instruction, determining whether the device protocol type corresponding to the current protocol channel matches the default device protocol type, and if so, executing step s 11; otherwise, go to step s 9;
step s 9: the device obtains an application identifier from the USB selection application instruction, determines whether the communication application corresponding to the application identifier is bound to the device protocol type corresponding to the current device protocol channel, and if so, executes step s 10; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step s 2;
step s 10: the equipment obtains a selection application instruction from the USB selection application instruction, and sends the selection application instruction to the communication application corresponding to the application identifier in the USB selection application instruction; receiving a select application response; packaging the selective application response according to the device protocol type corresponding to the current protocol channel to obtain a USB selective application response, returning the USB selective application response to the upper computer, and returning to the step s 2;
step s 11: the equipment acquires an application identifier and an application selection instruction from the USB application selection instruction, and sends the application selection instruction to the communication application corresponding to the application identifier in the USB application selection instruction; receiving a select application response; packaging the selective application response according to the device protocol type corresponding to the current protocol channel to obtain a USB selective application response, returning the USB selective application response to the upper computer, and returning to the step s 2;
after the step s2 determines that the command received through the current protocol channel is a USB communication command, the method further includes, before executing step s 8: judging whether the device protocol type corresponding to the current protocol channel is bound with the communication application, if so, executing the step s 8; if not, judging whether the equipment protocol type corresponding to the current protocol channel is matched with a default equipment protocol type, if so, obtaining a communication instruction from the USB communication instruction, and sending the communication instruction to the currently selected application; receiving a communication response returned by the application; packaging the communication response according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step s 2; otherwise, an error is reported to the upper computer through the current protocol channel, and the step s2 is returned.
9. The method according to claim 1, wherein the binding the device protocol type corresponding to the protocol identifier and the communication application corresponding to the application identifier specifically comprises: the equipment sets a binding identifier corresponding to the protocol identifier; correspondingly storing the application identifier and the protocol identifier;
the unbinding the device protocol type corresponding to the protocol identifier and the communication application corresponding to the application identifier specifically includes: the equipment resets a binding identifier corresponding to the protocol identifier; and deleting the application identifier stored corresponding to the protocol identifier.
10. The method according to claim 1, wherein said step s4 specifically comprises:
step s 41: the equipment organizes a selection application instruction comprising the application identifier, and sends the selection application instruction to the communication application corresponding to the application identifier; receiving a select application response;
step s 42: the device judges whether the application selection is successful according to the application selection response, and if so, the step s5 is executed; otherwise, an error is reported to the upper computer through the current protocol channel, and the step s2 is returned.
11. The method of claim 1, wherein before setting the own device protocol type according to the device protocol type of the bound communication application, the method further comprises:
the device judges whether the device protocol type of the current bound communication application is matched with the device protocol type of the current reported device, if so, the step s2 is returned; otherwise, setting the own device protocol type according to the device protocol type of the bound communication application, and returning to the step s 2.
12. The method according to claim 1 or 11, wherein the setting of the device protocol type of the device according to the device protocol type of the bound communication application includes: the equipment sets the own equipment protocol type according to the equipment protocol type of the current bound communication application or the equipment sets the own equipment protocol type according to the equipment protocol types of all the bound communication applications.
13. The method according to claim 1, wherein the device protocol type of the device is set according to the default device protocol type and the device protocol type of the bound communication application, and specifically comprises: the equipment judges whether the equipment protocol type of the bound communication application exists or not, and if so, the equipment protocol type of the equipment is set according to the equipment protocol type of the bound communication application; otherwise, setting the own device protocol type as the default device protocol type.
14. The method according to claim 13, wherein the setting of the device protocol type of the device according to the device protocol type of the bound communication application specifically includes: and setting the own device protocol type as one or more of the device protocol types of the bound communication application.
15. The method of claim 6, wherein applying further comprises: managing the application;
after the step s2 determines that the command received through the current protocol channel is a USB communication command, the method further includes, before executing step s 8: the device judges whether the device protocol type corresponding to the current protocol channel is bound with the communication application, if so, the step s8 is executed; otherwise, judging whether the management application is selected or not, if so, obtaining a communication instruction from the USB communication instruction, and sending the communication instruction to the selected management application; receiving a communication response returned by the management application; packaging the communication response according to the device protocol type corresponding to the current protocol channel to obtain a USB communication response, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step s 2; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step s 2;
in the step s9, after the device acquires the application identifier from the USB application selection instruction, the method further includes: judging the type of the application identifier, and if the type of the application identifier is the application identifier corresponding to the management application, executing step s 12; if the communication application is the application identifier corresponding to the communication application, determining whether the communication application corresponding to the application identifier is bound with the device protocol type corresponding to the current device protocol channel, if so, executing step s 10; otherwise, reporting an error to the upper computer through the current protocol channel, and returning to the step s 2;
step s 12: the equipment obtains a selection application instruction from the USB selection application instruction, and sends the selection application instruction to the management application corresponding to the application identifier in the USB selection application instruction; receiving a select application response; and packaging the selective application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selective application response, returning the USB selective application response to the upper computer through the current protocol channel, and returning to the step s 2.
16. The method of claim 1, wherein after step s3, step s4 is preceded by: the equipment judges whether the equipment protocol type corresponding to the protocol identification is bound with communication application, if so, the equipment reports an error to the upper computer through the current protocol channel, and the step s2 is returned; otherwise, go to step s 4;
after the step s6, before the step s7, the method further includes: the device judges whether the device protocol type corresponding to the protocol identification is bound with communication application, if so, the step s7 is executed; otherwise, an error is reported to the upper computer through the current protocol channel, and the step s2 is returned.
17. The method of claim 1, wherein the device comprises a first chip and a second chip; the communication application is installed on the second chip;
the method also comprises the following steps:
step a 1: the communication application waits for receiving an instruction, judges the type of the instruction after receiving the instruction from the first chip, and executes the step a2 after receiving the communication instruction; after receiving the application selection instruction, returning to an application selection response, and returning to the step a 1;
step a 2: the communication application judges whether the user key information needs to be acquired according to the communication instruction, if so, the step a3 is executed; otherwise, organizing a communication response comprising a first return code, returning the communication response to the first chip through the second chip, and returning to the step a 1;
step a 3: the communication application sets the key IO pin of the second chip as input, detects whether the level of the key IO pin of the second chip is low, and if so, executes the step a 4; otherwise, returning the communication response including the second return code to the first chip through the second chip, and returning to the step a 1;
step a 4: the communication application organizes a communication response comprising a first return code, returns the communication response comprising the first return code to the first chip through the second chip, sets a key IO pin of the second chip as an output, controls the second chip to output a low level to the key IO pin of the first chip, and returns to the step a 1;
the method comprises the following steps of packaging a communication response according to a device protocol type corresponding to a current protocol channel to obtain a USB communication response, and returning the USB communication response to an upper computer through the current protocol channel, and specifically comprises the following steps:
step h 1: the first chip in the device determines the type of the received communication response, and if the communication response is a communication response including a first return code, executes step h 2; if the communication response includes the second return code, executing step h 5;
step h 2: the first chip detects whether the key detection identifier is set, and if so, the step h3 is executed; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step s 2;
step h 3: the first chip sets a key IO pin of the first chip as input;
step h 4: the first chip judges whether the level of the key IO pin of the first chip is low, if so, resets the key detection identifier, closes the first timer, closes the key detection process, obtains a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returns the USB communication response to the upper computer through the current protocol channel, raises the level of the key IO pin of the first chip, and returns to the step s 2; otherwise, return to step h 4;
step h 5: the first chip judges whether the key detection mark is set, if so, a USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel, the USB communication response is returned to the upper computer through the current protocol channel, and the step s2 is returned; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step s 2; setting a key detection identifier, starting a first timer, and starting a key detection process; waiting for obtaining user key information within a first preset time specified by a first timer, and outputting a low level to a key IO pin of the second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
18. A method for dynamically matching the protocol type of a multi-protocol USB device with an application is characterized in that the application is installed on the device; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the method comprises the following steps:
step r 1: the equipment reports the equipment protocol type of the equipment to the upper computer;
step r 2: the device waits for receiving an instruction from an upper computer through a channel corresponding to the reported device protocol type, after the instruction is received, the channel receiving the instruction is used as a current protocol channel, the type of the instruction received through the current protocol channel is judged, and if the instruction received through the current protocol channel is a protocol switching instruction, the step r3 is executed; if the command received through the current protocol channel is a USB communication command, executing step r 6; if the instruction received through the current protocol channel is a USB application selection instruction, executing a step r 7;
step r 3: the equipment sets the protocol type of the equipment according to the protocol identification in the protocol switching instruction; organizing a protocol switching response according to the equipment protocol type corresponding to the current protocol channel, and returning the protocol switching response to the upper computer through the current protocol channel; returning to the step r 2;
step r 6: the equipment obtains a communication instruction from the USB communication instruction and sends the communication instruction to the currently selected application; receiving a communication response returned by the application; packaging a communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response, and returning the USB communication response to the upper computer through the current protocol channel; returning to the step r 2;
step r 7: the device obtains a selected application instruction from the USB selected application instruction, and sends the selected application instruction to an application corresponding to an application identifier in the selected application instruction; receiving a select application response; organizing the selected application response according to the device protocol type corresponding to the current protocol channel to obtain a USB selected application response, returning the USB selected application response to the upper computer through the current protocol channel, and returning to the step r 2.
19. The method of claim 18, wherein after r3, before returning to step r2, further comprising:
the device is reset and the device performs step r 1.
20. The method of claim 18, further comprising:
and when the upper computer receives the protocol switching response, the upper computer resets the equipment, and the equipment executes the step r 1.
21. The method of claim 18, further comprising: after the step r3, if the device is inserted into the upper computer again, the device executes a step r 1.
22. The method according to claim 18, wherein the step r1 specifically comprises:
the equipment acquires the equipment protocol type according to the equipment type parameter of the equipment, and reports the equipment protocol type of the equipment to the upper computer according to the acquired equipment protocol type;
the setting of the protocol type of the device according to the protocol identifier in the protocol switching instruction specifically includes: and updating the equipment type parameter according to the protocol identifier in the protocol switching instruction.
23. The method of claim 18, wherein the device comprises a first chip and a second chip; the communication application is installed on the second chip;
the method also comprises the following steps:
step a 1: the communication application waits for receiving an instruction from the first chip in the device, judges the type of the instruction after receiving the instruction from the first chip through the second chip, and executes the step a2 after receiving the communication instruction; after receiving the application selection instruction, returning to an application selection response, and returning to the step a 1;
step a 2: the communication application judges whether the user key information needs to be acquired according to the communication instruction, if so, the step a3 is executed; otherwise, organizing the communication response, returning the communication response to the first chip through the second chip, and returning to the step a 1;
step a 3: the communication application sets the key IO pin of the second chip as input, detects whether the level of the key IO pin of the second chip is low, and if so, executes the step a 4; otherwise, returning the communication response including the second return code to the first chip through the second chip, and returning to the step a 1;
step a 4: the communication application organizes a communication response comprising a first return code, returns the communication response comprising the first return code to the first chip through the second chip, sets a key IO pin of the second chip as an output, controls the second chip to output a low level to the key IO pin of the first chip, and returns to the step a 1;
the method comprises the following steps of packaging a communication response according to a device protocol type corresponding to a current protocol channel to obtain a USB communication response, and returning the USB communication response to an upper computer through the current protocol channel, and specifically comprises the following steps:
step h 1: the first chip in the device determines the type of the received communication response, and if the communication response is a communication response including a first return code, executes step h 2; if the communication response includes the second return code, executing step h 5;
step h 2: the first chip detects whether the key detection identifier is set, and if so, the step h3 is executed; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step s 2;
step h 3: the first chip sets a key IO pin of the first chip as input;
step h 4: the first chip judges whether the level of the key IO pin of the first chip is low, if so, resets the key detection identifier, closes the first timer, closes the key detection process, obtains a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returns the USB communication response to the upper computer through the current protocol channel, raises the level of the key IO pin of the first chip, and returns to the step r 2; otherwise, return to step h 4;
step h 5: the first chip judges whether the key detection mark is set, if so, a USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel, the USB communication response is returned to the upper computer through the current protocol channel, and the step r2 is returned; otherwise, obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel, returning the USB communication response to the upper computer through the current protocol channel, and returning to the step r 2; setting a key detection identifier, starting a first timer, and starting a key detection process; waiting for obtaining user key information within a first preset time specified by a first timer, and outputting a low level to a key IO pin of the second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
24. A multi-protocol USB device with a device protocol type dynamically matched with an application is characterized in that the application is installed on the device; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the apparatus comprises: the device comprises a reporting protocol type module, a first receiving module, a first judging module, a first obtaining module, a first selecting application module, a first binding module, a first returning module, a first setting module, a second obtaining module, a first unbinding module, a second setting module, a third obtaining module, a first sending module, a second receiving module and a first packaging module;
the report protocol type module is used for reporting one or more equipment protocol types of the equipment to the upper computer after the equipment is inserted into the upper computer;
the first receiving module is used for waiting for receiving the instruction from the upper computer through a channel corresponding to the reported device protocol type;
the first judging module is used for taking the channel receiving the instruction as a current protocol channel after the first receiving module receives the instruction, and judging the type of the instruction received by the current protocol channel;
the first obtaining module is configured to obtain a protocol identifier and an application identifier from the binding protocol instruction when the first determining module determines that the instruction received through the current protocol channel is the binding protocol instruction;
the first selection application module is used for selecting the communication application corresponding to the application identifier acquired by the first acquisition module;
the first binding module is configured to bind, after the first selected application module selects the communication application corresponding to the application identifier acquired by the first acquisition module, the device protocol type corresponding to the protocol identifier acquired by the first acquisition module and the communication application corresponding to the application identifier acquired by the first acquisition module;
the first returning module is used for returning a binding success response to the upper computer through the current protocol channel; returning a successful unbinding response to the upper computer through the current protocol channel; the USB communication response obtained by the first packaging module is returned to the upper computer through the current protocol channel;
the first setting module is configured to set the device protocol type of the device according to the device protocol type of the bound communication application after the first binding module binds the device protocol type corresponding to the protocol identifier acquired by the first acquiring module and the communication application corresponding to the application identifier acquired by the first acquiring module;
the second obtaining module is configured to obtain a protocol identifier and an application identifier from the unbinding protocol instruction when the first determining module determines that the instruction received through the current protocol channel is the unbinding protocol instruction;
the first unbinding module is configured to unbind the device protocol type corresponding to the protocol identifier acquired by the second acquiring module and the communication application corresponding to the application identifier acquired by the second acquiring module;
the second setting module is configured to set the device protocol type of the device according to the default device protocol type and the device protocol type of the bound communication application after the first unbinding module unbinds the device protocol type corresponding to the protocol identifier acquired by the second acquiring module and the communication application corresponding to the application identifier acquired by the second acquiring module;
the third obtaining module is used for obtaining a communication instruction from the USB communication instruction when the first judging module judges that the instruction received through the current protocol channel is the USB communication instruction;
the first sending module is configured to send the communication instruction obtained by the third obtaining module to a communication application bound to a device protocol type corresponding to a current protocol channel;
the second receiving module is used for receiving a communication response returned by the communication application bound with the equipment protocol type corresponding to the current protocol channel;
and the first packaging module is used for packaging the communication response received by the second receiving module according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response.
25. The apparatus of claim 24, further comprising: a reset module;
the reset module is used for resetting the equipment after the first setting module sets the equipment protocol type of the equipment according to the equipment protocol type bound with the communication application; when the second setting module sets the equipment protocol type of the equipment according to the default equipment protocol type and the equipment protocol type bound with the communication application, resetting the equipment;
and the report protocol type module is also used for reporting the equipment protocol type of the equipment to the upper computer after the reset module resets the equipment.
26. The apparatus of claim 24, further comprising: the second judgment module and the first error reporting module;
the second judging module is configured to judge whether the device protocol type corresponding to the current protocol channel is bound with a communication application after the first judging module judges that the instruction received through the current protocol channel is a USB communication instruction;
the third obtaining module is specifically configured to obtain a communication instruction from the USB communication instruction after the second determining module determines that the communication instruction is received;
and the first error reporting module is used for reporting errors to the upper computer through the current protocol channel after the second judging module judges that the second judging module is not the first judging module.
27. The apparatus of claim 24, further comprising: the device comprises a fourth acquisition module, a third judgment module, a second error reporting module, a fifth acquisition module, a second sending module, a third receiving module and a second packaging module;
the fourth obtaining module is configured to obtain an application identifier from the USB selection application instruction when the first determining module determines that the instruction received through the current protocol channel is the USB selection application instruction;
the third judging module is configured to judge whether the communication application corresponding to the application identifier acquired by the fourth acquiring module is bound to the device protocol type corresponding to the current device protocol channel;
the second error reporting module is used for reporting errors to the upper computer through the current protocol channel after the third judging module judges that the third judging module is negative;
the fifth obtaining module is configured to obtain an application selection instruction from the USB application selection instruction after the third determining module determines that the application selection instruction is positive;
the second sending module is configured to send the application selection instruction obtained by the fifth obtaining module to the communication application corresponding to the application identifier in the USB application selection instruction;
the third receiving module is used for receiving a response of selecting the application;
the second packaging module is used for packaging the selected application response received by the third receiving module according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selected application response;
the first returning module is also used for returning the USB selection application response to the upper computer.
28. The device according to claim 24, wherein the reporting protocol type module is specifically configured to obtain a device protocol type according to a device type parameter of the device, and report one or more of the device protocol types of the device to the upper computer according to the obtained device protocol type;
the first setting module is specifically configured to update a device type parameter of the first setting module according to a device protocol type of a bound communication application after the first binding module binds a device protocol type corresponding to the protocol identifier acquired by the first acquiring module and the communication application corresponding to the application identifier acquired by the first acquiring module;
the second setting module is specifically configured to update the device type parameter of the first unbinding module according to the default device protocol type and the device protocol type of the bound communication application after the first unbinding module unbinds the device protocol type corresponding to the protocol identifier acquired by the second acquiring module and the communication application corresponding to the application identifier acquired by the second acquiring module.
29. The apparatus of claim 24, further comprising: the device comprises a fourth judging module, a sixth acquiring module, a seventh acquiring module, a fifth judging module, a third error reporting module, an eighth acquiring module, a sixth judging module, a seventh judging module and a ninth acquiring module;
the fourth judging module is configured to, when the first judging module judges that the instruction received through the current protocol channel is a USB selection application instruction, judge whether the device protocol type corresponding to the current protocol channel matches a default device protocol type;
the sixth obtaining module is configured to, after the fourth determining module determines that the application identifier is included in the USB selection application instruction, obtain an application identifier and a selection application instruction from the USB selection application instruction, and send the selection application instruction to the communication application corresponding to the application identifier in the USB selection application instruction; receiving a select application response; packaging the selective application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selective application response;
the seventh obtaining module is configured to obtain an application identifier from the USB selection application instruction after the fourth determining module determines that the application identifier is not included in the application identifier;
the fifth judging module is configured to judge whether the communication application corresponding to the application identifier acquired by the seventh acquiring module is bound to the device protocol type corresponding to the current device protocol channel;
the eighth obtaining module is configured to obtain a selected application instruction from the USB selected application instruction and send the selected application instruction to the communication application corresponding to the application identifier in the USB selected application instruction after the fifth determining module determines that the application identifier is the application identifier; receiving a select application response; packaging the selective application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selective application response;
the third error reporting module is used for reporting an error to the upper computer through the current protocol channel after the fifth judging module judges that the error is not the case; when the seventh judging module judges that the protocol is not correct, an error is reported to the upper computer through the current protocol channel;
the sixth judging module is configured to, after the first judging module judges that the instruction received through the current protocol channel is a USB communication instruction, judge whether a device protocol type corresponding to the current protocol channel is bound to a communication application;
the third obtaining module is specifically configured to obtain a communication instruction from the USB communication instruction after the sixth determining module determines that the communication instruction is received;
the seventh judging module is configured to, after the sixth judging module judges that the device protocol type corresponding to the current protocol channel is not matched with the default device protocol type, judge whether the device protocol type corresponding to the current protocol channel is matched with the default device protocol type;
the ninth obtaining module is configured to obtain a communication instruction from the USB communication instruction and send the communication instruction to the currently selected application after the seventh determining module determines that the USB communication instruction is received; receiving a communication response returned by the application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response;
the first returning module is further configured to return the USB selective application response obtained by the sixth obtaining module, the USB selective application response obtained by the eighth obtaining module, and the USB communication response obtained by the ninth obtaining module to the upper computer through the current protocol channel.
30. The device according to claim 24, wherein the first binding module is specifically configured to set a binding identifier corresponding to the protocol identifier acquired by the first acquiring module; correspondingly storing the application identifier acquired by the first acquisition module and the protocol identifier acquired by the first acquisition module;
the first unbinding module is specifically configured to reset a binding identifier corresponding to the protocol identifier acquired by the second acquiring module; and deleting the application identifier stored corresponding to the protocol identifier acquired by the second acquisition module.
31. The device according to claim 24, wherein the first selected application module specifically comprises: the device comprises a first organization unit, a first sending unit, a first receiving unit, a first judging unit and a first error reporting unit;
the first organizing unit is configured to organize a selected application instruction including the application identifier acquired by the first acquiring module;
the first sending unit is configured to send the application selection instruction organized by the first organization unit to a communication application corresponding to the application identifier acquired by the first acquisition module;
the first receiving unit is used for receiving a response of selecting the application;
the first judging unit is used for judging whether the selected application is successful according to the selected application response received by the first receiving unit;
the first binding module is specifically configured to bind, after the first determining unit determines that the communication application is the communication application, the device protocol type corresponding to the protocol identifier acquired by the first acquiring module and the communication application corresponding to the application identifier acquired by the first acquiring module;
and the first error reporting unit is used for reporting errors to the upper computer through the current protocol channel after the first judging unit judges that the first protocol channel is not the first protocol channel.
32. The apparatus of claim 24, further comprising: an eighth judging module;
the eighth determining module is configured to determine whether the device protocol type of the currently bound communication application matches the currently reported device protocol type after the first binding module binds the device protocol type corresponding to the protocol identifier acquired by the first acquiring module and the communication application corresponding to the application identifier acquired by the first acquiring module;
the first setting module is specifically configured to set the device protocol type of the device according to the device protocol type of the bound communication application after the eighth determining module determines that the device protocol type of the device is not the device protocol type of the bound communication application.
33. The device according to claim 24 or 32, wherein the first setting module is specifically configured to: after the first binding module binds the device protocol type corresponding to the protocol identifier acquired by the first acquisition module with the communication application corresponding to the application identifier acquired by the first acquisition module, setting the device protocol type of the device according to the device protocol type of the currently bound communication application or setting the device protocol type of the device according to the device protocol types of all the bound communication applications.
34. The device according to claim 24, wherein the second setting module specifically includes: a second judging unit and a first setting unit;
the second determining unit is configured to determine whether a device protocol type of a bound communication application exists after the first unbinding module unbinds the device protocol type corresponding to the protocol identifier acquired by the second acquiring module and the communication application corresponding to the application identifier acquired by the second acquiring module;
the first setting unit is used for setting the own device protocol type according to the device protocol type bound with the communication application after the second judging unit judges that the device protocol type is the true device protocol type; and when the second judgment unit judges that the equipment protocol type of the equipment is not the default equipment protocol type, setting the equipment protocol type of the equipment as the default equipment protocol type.
35. The device according to claim 34, wherein the first setting unit is specifically configured to set the device protocol type of the first setting unit to one or more of the device protocol types of the bound communication applications after the second determining unit determines that the first setting unit is yes; and when the second judgment unit judges that the equipment protocol type of the equipment is not the default equipment protocol type, setting the equipment protocol type of the equipment as the default equipment protocol type.
36. The apparatus of claim 27, wherein the applying further comprises: managing the application; the apparatus further comprises: the device comprises a tenth judging module, an eleventh judging module, a fourth error reporting module, a tenth acquiring module, a twelfth judging module and an eleventh acquiring module;
the tenth judging module is configured to, after the first judging module judges that the instruction received through the current protocol channel is a USB communication instruction, judge whether a device protocol type corresponding to the current protocol channel is bound to a communication application;
the third obtaining module is specifically configured to obtain a communication instruction from the USB communication instruction after the tenth determining module determines that the communication instruction is positive;
the eleventh judging module is configured to judge whether the management application has been selected or not after the tenth judging module judges that the management application has not been selected;
the tenth obtaining module is configured to, after the eleventh determining module determines that the USB communication command is the USB communication command, obtain a communication command from the USB communication command, and send the communication command to the selected management application; receiving a communication response returned by the management application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response;
the fourth error reporting module is used for reporting an error to the upper computer through the current protocol channel after the eleventh judging module judges that the error is not the case;
the twelfth judging module is configured to judge the type of the application identifier acquired by the fourth acquiring module;
the eleventh acquiring module is configured to, when the twelfth judging module judges that the application identifier acquired by the fourth acquiring module is an application identifier corresponding to a management application, obtain a selected application instruction from the USB selected application instruction, and send the selected application instruction to the management application corresponding to the application identifier in the USB selected application instruction; receiving a select application response; packaging the selective application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selective application response;
the third determining module is specifically configured to determine, when the twelfth determining module determines that the application identifier obtained by the fourth obtaining module is the application identifier corresponding to the communication application, whether the communication application corresponding to the application identifier is bound to the device protocol type corresponding to the current device protocol channel;
the first returning module is also used for returning the USB selection application response acquired by the eleventh acquiring module to the upper computer through the current protocol channel; and returning the USB communication response acquired by the tenth acquisition module to the upper computer through the current protocol channel.
37. The apparatus of claim 24, further comprising: a thirteenth judging module, a fourteenth judging module and a fifth error reporting module;
the thirteenth judging module is configured to, after the first obtaining module obtains a protocol identifier and an application identifier from the binding protocol instruction, judge whether a device protocol type corresponding to the protocol identifier obtained by the first obtaining module is bound with a communication application;
the first selection application module is specifically configured to select, after the thirteenth determining module determines that the communication application corresponds to the application identifier acquired by the first acquiring module;
the fourteenth determining module is configured to determine whether the device protocol type corresponding to the protocol identifier acquired by the second acquiring module is bound with the communication application after the second acquiring module acquires the protocol identifier and the application identifier from the unbinding protocol instruction;
the first unbinding module is specifically configured to, after the fourteenth determining module determines that the protocol identifier is the application identifier, unbind the device protocol type corresponding to the protocol identifier acquired by the second acquiring module and the communication application corresponding to the application identifier acquired by the second acquiring module;
the fifth error reporting module is used for reporting an error to the upper computer through the current protocol channel after the thirteenth judging module judges that the error is positive; and when the fourteenth judging module judges that the protocol is not the protocol channel, reporting an error to the upper computer through the current protocol channel.
38. The apparatus of claim 24, wherein the apparatus comprises a first chip and a second chip; the communication application is installed on the second chip;
the first chip includes: the device comprises a reporting protocol type module, a first receiving module, a first judging module, a first obtaining module, a first selecting application module, a first binding module, a first returning module, a first setting module, a second obtaining module, a first unbinding module, a second setting module, a third obtaining module, a first sending module, a second receiving module and a first packaging module;
the second chip includes: the system comprises a fourth receiving module, a fourteenth judging module, a fifteenth judging module, a first organizing module, a third sending module, a third setting module, a first detecting module, a fourth setting module and a first control module;
the fourth receiving module is used for receiving an instruction from the first chip;
the fourteenth judging module is configured to judge the type of the instruction received by the fourth receiving module;
the fifteenth judging module is configured to, after the fourteenth judging module judges that the type of the instruction is the communication instruction, judge whether it is necessary to acquire user key information according to the communication instruction;
the first organizing module is configured to organize a communication response including a first return code when the fifteenth determining module determines that the communication response is not received; when the first detection module detects that the communication response is positive, organizing a communication response comprising a first return code;
the third sending module is configured to return the communication response organized by the first organizing module to the first chip; and when the first detection module detects that the communication response is negative, the communication response including a second return code is returned to the first chip;
the third setting module is configured to set the key IO pin of the second chip as input after the fifteenth determining module determines that the key IO pin is input; when the first detection module detects that the input/output (IO) pin of the second chip is output;
the first detection module is used for detecting whether the level of a key IO pin of the second chip is low;
the first control module is used for controlling the second chip to output a low level to a key IO pin of the first chip after the first detection module detects that the first chip is the power supply module;
the first package module specifically includes: the device comprises a third judging unit, a first detecting unit, a first packaging unit, a second setting unit, a fourth judging unit, a first resetting unit, a first pulling-up unit, a second detecting unit and a key detecting unit;
the third judging unit is used for judging the type of the received communication response;
the first detection unit is used for detecting whether the key detection identifier is set or not when the third judgment unit judges that the type of the received communication response is the communication response comprising the first return code;
the first packaging unit is used for obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel after the first detection unit detects that the equipment protocol type and the communication response are not the same; when the fourth judging unit judges that the communication command is the communication response comprising the second return code, the USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel;
the second setting unit is used for setting the key IO pin of the first chip as input after the first detection unit detects that the key IO pin is input;
the fourth judging unit is configured to judge whether the level of the key IO pin of the fourth judging unit is low after the second setting unit sets the key IO pin of the first chip as input; judging whether the level of the IO pin of the key is low or not when the IO pin of the key is judged to be not;
the first resetting unit is used for resetting the key detection identifier, closing the first timer and closing the key detection process after the fourth judging unit judges that the key detection identifier is the first key detection identifier;
the first pull-up unit is used for pulling up the level of the key IO pin of the first chip after the fourth judgment unit judges that the first chip is the power supply;
the second detection unit is used for judging whether the key detection identifier is set or not when the third judgment unit judges that the type of the received communication response is the communication response comprising the second return code;
the key detection unit is used for setting a key detection identifier, starting a first timer and starting a key detection process after the second detection unit detects that the key detection identifier is not set; waiting for obtaining user key information within a first preset time specified by a first timer, and outputting a low level to a key IO pin of the second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
39. A multi-protocol USB device with a device protocol type dynamically matched with an application is characterized in that the application is installed on the device; the application comprises the following steps: communication application; the equipment is inserted into an upper computer; the apparatus comprises: the device comprises a reporting protocol type module, a first receiving module, a first judging module, a first setting module, a first returning module, a first obtaining module and a second obtaining module;
the reporting protocol type module is used for reporting the equipment protocol type of the equipment to the upper computer after the equipment is inserted into the upper computer;
the first receiving module is used for receiving an instruction from the upper computer through a channel corresponding to the reported device protocol type;
the first judging module is used for taking the channel receiving the instruction as a current protocol channel after the first receiving module receives the instruction, and judging the type of the instruction received by the current protocol channel;
the first setting module is used for setting the own equipment protocol type according to the protocol identifier in the protocol switching instruction when the first judging module judges that the instruction received through the current protocol channel is the protocol switching instruction;
the first returning module is used for organizing a protocol switching response according to the equipment protocol type corresponding to the current protocol channel and returning the protocol switching response to the upper computer through the current protocol channel; the USB communication response is returned to the upper computer through the current protocol channel; returning the USB selection application response to the upper computer through the current protocol channel;
the first obtaining module is used for obtaining a communication instruction from the USB communication instruction and sending the communication instruction to the currently selected application when the first judging module judges that the instruction received through the current protocol channel is the USB communication instruction; receiving a communication response returned by the application; packaging the communication response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB communication response;
the second obtaining module is used for obtaining a selected application instruction from the USB selected application instruction and sending the selected application instruction to an application corresponding to an application identifier in the selected application instruction when the first judging module judges that the instruction received through the current protocol channel is the USB selected application instruction; receiving a select application response; and organizing the selected application response according to the equipment protocol type corresponding to the current protocol channel to obtain a USB selected application response.
40. The apparatus of claim 39, further comprising: a reset module;
the reset module is used for resetting the equipment after the first return module returns a protocol switching response to the upper computer through the current protocol channel;
and the report protocol type module is also used for reporting the equipment protocol type of the equipment to the upper computer after the reset module resets the equipment.
41. The device according to claim 39, wherein the reporting protocol type module is specifically configured to obtain a device protocol type according to a device type parameter of the device, and report the device protocol type of the device to the upper computer according to the obtained device protocol type;
the first setting module is specifically configured to update the device type parameter according to a protocol identifier in the protocol switching instruction when the first determining module determines that the instruction is the protocol switching instruction.
42. The apparatus of claim 39, wherein the apparatus comprises a first chip and a second chip; the communication application is installed on the second chip;
the first chip includes: the device comprises a reporting protocol type module, a first receiving module, a first judging module, a first setting module, a first returning module, a first obtaining module and a second obtaining module;
the second chip includes: the device comprises a second receiving module, a second judging module, a third judging module, a first organizing module, a first sending module, a second setting module, a first detecting module, a third setting module and a first control module;
the second receiving module is used for receiving an instruction from the first chip;
the second judging module is used for judging the type of the instruction received by the second receiving module;
the third judging module is used for judging whether the user key information needs to be acquired according to the communication instruction after the second judging module judges that the type of the instruction is the communication instruction;
the first organizing module is used for organizing the communication response comprising the first return code after the third judging module judges that the communication response comprises the first return code; when the first detection module detects that the communication response is positive, organizing a communication response comprising a first return code;
the first sending module is used for returning the communication response organized by the first organizing module to the first chip; and when the first detection module detects that the communication response is negative, the communication response including a second return code is returned to the first chip;
the second setting module is used for setting the key IO pin of the second chip as input after the third judging module judges that the second chip is yes; when the first detection module detects that the input/output (IO) pin of the second chip is output;
the first detection module is used for detecting whether the level of a key IO pin of the second chip is low;
the first control module is used for controlling the second chip to output a low level to a key IO pin of the first chip after the first detection module detects that the first chip is the power supply module;
the first obtaining module specifically includes: the device comprises a first acquisition unit, a first sending unit, a first receiving unit and a first packaging unit;
the first obtaining unit obtains a communication instruction from the USB communication instruction when the first judging module judges that the instruction is the USB communication instruction;
the first sending unit is used for sending the communication instruction to the currently selected application;
the first receiving unit is used for receiving a communication response returned by the currently selected application;
the first packaging unit specifically includes: the device comprises a first judgment subunit, a first detection subunit, a first packaging subunit, a first setting subunit, a second judgment subunit, a first resetting subunit, a first pull-up subunit, a second detection subunit and a key detection subunit;
the first judging subunit is used for judging the type of the received communication response;
the first detection subunit is configured to detect whether the key detection identifier is set when the first judgment subunit judges that the type of the received communication response is a communication response including a first return code;
the first packaging subunit is used for obtaining a USB communication response according to the equipment protocol type and the communication response corresponding to the current protocol channel after the first detection subunit detects that the equipment protocol type and the communication response are not the same as the current protocol channel; when the second judging subunit judges that the communication instruction is the communication response comprising the second return code, the USB communication response is obtained according to the equipment protocol type and the communication response corresponding to the current protocol channel;
the first setting subunit is configured to set, when the first detection subunit detects that the input is positive, a key IO pin of the first chip as an input;
the second judging subunit is configured to judge whether a level of a key IO pin of the second chip is low after the first setting subunit sets the key IO pin of the first chip as input; judging whether the level of the IO pin of the key is low or not when the IO pin of the key is judged to be not;
the first resetting subunit is configured to reset the key detection identifier, close the first timer, and close the key detection process after the second determining subunit determines that the key detection identifier is valid;
the first pull-up subunit is configured to pull up a key IO pin level of the first chip after the second determination subunit determines that the first chip is a power supply;
the second detection subunit is configured to, when the first judgment subunit judges that the type of the received communication response is a communication response including a second return code, judge whether the key detection identifier is set;
the key detection subunit is used for setting a key detection identifier, starting a first timer and starting a key detection process after the second detection subunit detects that the key detection identifier is not the first key detection identifier; waiting for obtaining user key information within a first preset time specified by a first timer, and outputting a low level to a key IO pin of the second chip after obtaining the user key information within the first preset time; and resetting the key detection identifier, closing the first timer and closing the key detection process after the user key information is not acquired within the first preset time.
CN201810748683.7A 2018-07-10 2018-07-10 Method and device for dynamically matching protocol type and application of multi-protocol USB device Active CN108920389B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810748683.7A CN108920389B (en) 2018-07-10 2018-07-10 Method and device for dynamically matching protocol type and application of multi-protocol USB device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810748683.7A CN108920389B (en) 2018-07-10 2018-07-10 Method and device for dynamically matching protocol type and application of multi-protocol USB device

Publications (2)

Publication Number Publication Date
CN108920389A CN108920389A (en) 2018-11-30
CN108920389B true CN108920389B (en) 2020-02-11

Family

ID=64410768

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810748683.7A Active CN108920389B (en) 2018-07-10 2018-07-10 Method and device for dynamically matching protocol type and application of multi-protocol USB device

Country Status (1)

Country Link
CN (1) CN108920389B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111339522A (en) * 2019-05-15 2020-06-26 深圳市文鼎创数据科技有限公司 Online quick identity authentication method, online quick identity authentication device and card reader
CN111045750B (en) * 2019-12-19 2023-07-07 飞天诚信科技股份有限公司 Method for automatically matching application programs on multi-application device and electronic device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20080093725A (en) * 2007-04-18 2008-10-22 주식회사 케이티프리텔 Terminal unit for providing ip multimedia service on the basis of session initiaion protocol, call session control function device, method of transmitting and receiving thereof
CN101610290A (en) * 2009-07-22 2009-12-23 深圳市茁壮网络股份有限公司 The method of download management and download management unit and download system
CN103166963A (en) * 2013-03-05 2013-06-19 汉柏科技有限公司 Protocol identification method and system for de-encapsulation

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20080093725A (en) * 2007-04-18 2008-10-22 주식회사 케이티프리텔 Terminal unit for providing ip multimedia service on the basis of session initiaion protocol, call session control function device, method of transmitting and receiving thereof
CN101610290A (en) * 2009-07-22 2009-12-23 深圳市茁壮网络股份有限公司 The method of download management and download management unit and download system
CN103166963A (en) * 2013-03-05 2013-06-19 汉柏科技有限公司 Protocol identification method and system for de-encapsulation

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"物联网信息完整性保护方案";朱鹏飞等;《NeTINFO SECURITY》;20171231;全文 *

Also Published As

Publication number Publication date
CN108920389A (en) 2018-11-30

Similar Documents

Publication Publication Date Title
US9411990B2 (en) Working method of a multi-slot card reader based on the standard CCID protocol
CN101553783B (en) For receiving the system and method for control command at ancillary equipment
US8001304B2 (en) Portable memory device with multiple I/O interfaces wherein each I/O interface has respective protocol and device parameters are requested from one I/O interface using only respective protocol
US7137565B2 (en) Method and algorithm for accessing a smart card stored in a telecommunications card from a host device to which said telecommunications is connected
EP2421216A1 (en) Enhanced near field communication terminal, smart card and communication method thereof
US20080126584A1 (en) System and Method for Receiving Control Commands at a Peripheral Device
US8408474B2 (en) Method for speeding up the detection and the activation of the communication interface between a terminal and a UICC
CN108920389B (en) Method and device for dynamically matching protocol type and application of multi-protocol USB device
CN114138333B (en) Program loading method and related device
US11212658B2 (en) Method for providing near filed communication device information for user and system therefor
US20130225074A1 (en) Non-volatile memory for nfc router
CN105208508A (en) Intelligent device, wearable device, installation package pushing method, installation package receiving method
US8793651B2 (en) Remote card content management using synchronous server-side scripting
CN107844305A (en) The method for upgrading software and embedded device of embedded device
CN109446120B (en) USB device and method for identifying MacOS system by USB device
KR20020036717A (en) Microcomputer and method for controlling the same
CN102708032B (en) Method and device for detecting hot plug of secure digital card
WO2010118612A1 (en) Method for installing contactless payment application, smart card and mobile terminal
US20070198753A1 (en) Method and protocol for transmitting extended commands to USB devices
CN108989428B (en) Bluetooth terminal upgrading method, server, computer readable storage medium and system
US20100235393A1 (en) Portable electronic device and access control method in portable electronic device
CN112905212A (en) Firmware data processing method, device, equipment and storage medium
US7930458B2 (en) USB memory card reader having memory card identification
JP7397402B2 (en) Electronic information storage medium, data transmission method, and program
KR101570662B1 (en) Methods and systems for communicating with a non-volatile memory storage device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant