WO2012034524A1 - Usb设备识别主机windows操作系统版本类型的方法 - Google Patents

Usb设备识别主机windows操作系统版本类型的方法 Download PDF

Info

Publication number
WO2012034524A1
WO2012034524A1 PCT/CN2011/079679 CN2011079679W WO2012034524A1 WO 2012034524 A1 WO2012034524 A1 WO 2012034524A1 CN 2011079679 W CN2011079679 W CN 2011079679W WO 2012034524 A1 WO2012034524 A1 WO 2012034524A1
Authority
WO
WIPO (PCT)
Prior art keywords
operating system
host
usb
usb device
identifier
Prior art date
Application number
PCT/CN2011/079679
Other languages
English (en)
French (fr)
Inventor
陆舟
于华章
Original Assignee
飞天诚信科技股份有限公司
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 飞天诚信科技股份有限公司 filed Critical 飞天诚信科技股份有限公司
Priority to US13/640,997 priority Critical patent/US8862790B2/en
Publication of WO2012034524A1 publication Critical patent/WO2012034524A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • G06F9/4411Configuring for operating with peripheral devices; Loading of device drivers

Definitions

  • the present invention relates to the field of computer operating systems, and in particular to a method for a USB device to identify a host Windows operating system version type. Background technique
  • the USB protocol technology is a serial bus standard for connecting a host to an external device. It is widely used on hosts (such as personal computers, personal digital assistants, and mobile computers). It supports hot plug and plug and play, and supports bus power. Almost all peripheral devices such as mouse, keyboard, gamepad, scanner, digital camera, printer, hard disk, security device, optical drive and network card can be connected to and communicated with the host by running the USB interface.
  • the USB interface has become the current majority. The default interface to which the host peripheral is connected to the computer.
  • the device may have to know the type of operating system running on the host computer it is connected to. However, in the prior art, the device does not recognize the host operating system.
  • a method for a USB device to identify a version of a Windows operating system version of a host includes: Step A: USB device And performing initialization; step B, the USB device performs USB enumeration, and determines whether the first preset command is received during the USB enumeration process, and if yes, determines that the host operating system is the first operating system, Step D is performed. Otherwise, step C is performed. Step C: The USB device determines a device type returned to the host during the USB enumeration process.
  • the USB device determines whether there is a second preset command in the received command, and if the second preset command exists, determining that the host operating system is the second operating system, if the second preset command does not exist, Determining that the host operating system is the third operating system;
  • the USB device receives the SCSI command issued by the host, and determines that the received second SCSI command is a third preset command.
  • the USB device establishes communication with the host, and waits to receive an instruction sent by the host, and returns corresponding information to the host according to the determined host operating system type.
  • the initializing includes: initializing the device type identifier to a default device type identifier.
  • the initializing further includes: initializing the power-on identifier to a first preset value, and initializing the device type identifier to a default device type identifier.
  • the USB device determines that the device type returned to the host during the USB enumeration is: the USB device determines the returned device type according to the device type identifier returned in the USB enumeration process.
  • the method further includes: after the USB device determines that the host operating system type is the first operating system, the second operating system, or the third operating system, setting the device type identifier to the first device type, the second device type, or the first Three device types.
  • the step D further includes: the USB device determining whether the current device type identifier is the same as the default device type identifier.
  • the USB device communicates with the host, and waits to receive an instruction sent by the host; if not, The USB device performs soft power-down processing, and sets the power-on identifier to a second preset value, and performs step A.
  • the initializing further includes: initializing the power-on identifier to a first preset value, and initializing the operating system type identifier to a default operating system type identifier.
  • the method further includes: the USB device storing a mapping table of an operating system type identifier and a device type identifier.
  • the USB device determines that the device type returned in the USB enumeration process is: the USB device searches the mapping table according to the default operating system type identifier to obtain a corresponding device type identifier, according to the device type identifier obtained by the searching. Determine the type of device returned.
  • the method further includes: after the USB device determines that the host operating system type is the first operating system, the second operating system, or the third operating system, setting the operating system type identifier as the first preset identifier, and the second preset The identifier or the third preset identifier.
  • the step D further includes: the USB device determining whether the current operating system type identifier is the same as the default operating system type identifier, and if the same, the USB device establishes communication with the host, and waits to receive the delivery by the host. If the command is not the same, the USB device performs a soft power-down process, and sets the power-on flag to a second preset value, and performs the step.
  • the method further includes: determining whether the USB device is powered on for the first time, and if it is powering on for the first time, performing step B; if not, the USB device performing step D. Determining whether the USB device is powered on for the first time is: determining whether the power-on identifier is the first preset value.
  • the device type returned by the USB device to the host further includes an HID device.
  • the first preset command is a device configuration descriptor command; the second preset command is a device status command; and the second SCSI command is a device information instruction.
  • the USB device determines, according to the content of the command field of the second SCSI command, when When the command field content of the second SCSI command is the first preset content, the second instruction is the third preset command; when the command domain content of the second SCSI command is the second preset content The second instruction is the fourth preset command.
  • the first operating system is Windows XP
  • the second operating system is Windows 7
  • the third operating system is Windows Vista.
  • FIG. 1 is a flowchart of a method for a USB device to identify a Windows operating system version type of a host according to Embodiment 1 of the present invention
  • FIG. 2 is a USB device identifying a host Windows operating system version type according to Embodiment 2 of the present invention
  • Method flow chart
  • FIG. 3 is a flowchart of a method for a USB device to identify a version of a Windows operating system version of a host according to Embodiment 3 of the present invention.
  • the communication between the USB device and the host is: The host sends a command to the USB device, and the USB device responds to the received command.
  • the basic unit of communication between the USB device and the host is a "package", wherein, the classification of the "package” The main ones are: token packets, data packets, and handshake packets.
  • the PID determines the specific type of the packet.
  • the format of the token packet is SYNC+PID+ADDR+E DP+CRC; the data packet is divided into DATA0 packet and DATA1 packet. When the data length returned by the USB device exceeds the maximum output packet length of the corresponding endpoint, it needs to be returned. The data is sent in batches. In general, the DATA0 packet and the DATA1 packet are sent alternately; the format of the handshake packet is: SYNC+PID.
  • the USB device communicates with the host through the device endpoint. E.g:
  • PID ACK idle: 2ela
  • the above command indicates that the packet is a SETUP packet, the data content is 80 06 00 01 00 00 40 00, and the handshake packet is ACK.
  • the SETUP packet is delivered by the host, and the USB device receives the SETUP packet. Return a response message to the host, for example:
  • the response data returned by the USB device to the host is 12 01 10 01 00 00 00 08. It should be noted that the USB device returns the response data to the host after receiving the token packet of the IN or OUT sent by the host; thus, USB The information exchange between the device and the host is completed, and each information exchange is started by receiving the SETUP packet sent by the host.
  • the USB device can be further classified into a CCID device, a SCSI device, and an HID device according to a communication protocol (CCID, SCSI, or HID protocol) used for data communication between the USB device and the host.
  • Embodiment 1 This embodiment provides a method for a USB device to identify a host Windows operating system version type.
  • the Windows operating system version type is divided according to different kernels, and is represented by Windows XP, Windows Vista, and Windows 7. See Figure 1, the specific method is as follows:
  • the USB device is powered on and initialized.
  • the USB device specifically includes: a security device (such as a USB Key), a card reader, etc.; specifically, the USB device is connected to the host through the USB bus, and is powered from the host Vcc (power supply voltage)
  • the working voltage is obtained at the operating voltage or the operating system.
  • the initialization operation includes: the USB device initializes the power-on identifier and the operating system identifier stored in the USB device to the default identifier.
  • the default power-on identifier is the first preset value, and the default operating system identifier.
  • the host operating system constantly monitors whether there is device access on the USB bus, specifically by detecting the change of the Vcc pull-up resistor, and detecting the USB device access. , load the device bus driver, start enumerating the USB device, as shown in 102 to 106. 102.
  • USB device bus reset It should be noted that after the USB device bus is reset, the default address 0 of the USB device is enabled. Next, the USB device and the host transmit the command and data through the address 0.
  • the USB device determines whether it is powered on for the first time. If not, execute 104; if yes, execute 105; determine whether the USB device is powered on for the first time: determining whether the power-on identifier is the first preset value, and if so, The USB device is powered on for the first time. Otherwise, it is not powered on for the first time.
  • the USB device completes the enumeration according to the current operating system identifier, and establishes communication with the host, and waits for receiving an instruction issued by the host.
  • the USB device receives a series of setup packets sent by the host, and completes the USB enumeration according to the default operating system identifier. Specifically, the host operating system corresponding to the default operating system identifier sends a series of setup packets to the USB device, and enumerates the USB devices to obtain description information of the USB device.
  • the USB device receives a series of setup packages delivered by the host, including "fetch device descriptor”, “set device address”, “take configuration descriptor”, “take endpoint descriptor”, “take string descriptor”, “take”
  • the endpoint descriptor "" selects the configuration" command, and the USB device responds to it one by one.
  • the USB device determines whether there is a first preset command in the USB enumeration process, and if yes, executes 107; if not, executes 108; specifically, the first preset command is a configuration descriptor command; specifically, The configuration descriptor command is: 80 06 00 02 00 00 09 00.
  • the USB device determines that the host operating system is the first operating system, and sets the operating system identifier as the first preset identifier, and executes 116; specifically, the first operating system is Windows XP;
  • the USB device determines, according to the default operating system identifier, which device type returned by the USB enumeration process is a CCID device, a SCSI device, and a HID device, and if it is a CCID device, executes 109; If it is a SCSI device, execute 112; if it is a HID device, execute 115; specifically, in the USB enumeration process, after the USB device receives the "fetch device descriptor" information sent by the host, the operating system identifier and the device type In the mapping table of the identifier, find the device type corresponding to the operating system identifier, and return the obtained device type to the host.
  • the mapping table of the operating system identifier and the device type identifier is preset and stored in the USB device; thus, when the USB device determines the returned device type, the mapping table of the operating system identifier and the device type identifier may be adopted.
  • the device type is confirmed according to the operating system identifier; for example, the first preset identifier maps the CCID device identifier, the second preset identifier maps the SCSI device identifier, and the third preset identifier maps the HID device identifier, the shell 1", when the operating system
  • the USB device knows that the returned device type is a CCID device according to the identifier.
  • the USB device receives the CCID command sent by the host CCID driver, and determines whether there is a second preset command in the received command. If it does not exist, execute 110, if yes, execute 111; before the host receives the USB After the device returns the information of the CCID device itself, it loads the corresponding
  • the CCID driver establishes communication between the USB device and the host, waiting to receive commands issued by the CCID driver.
  • the second preset command is a device status command; specifically, the device status command is 80 00 00 00 00 00 02 00.
  • the USB device determines that the host operating system is the third operating system, and sets the current operating system identifier to the third preset identifier, and executes 116.
  • the third operating system is Windows Vista.
  • the USB device determines that the host operating system is the second operating system, and sets the current operating system identifier to the second preset identifier, and executes 116. Specifically, the second operating system is Windows 7. 112.
  • the USB device receives the SCSI command sent by the SCSI driver, and determines whether the received second SCSI command is a third preset command or a fourth preset command. If the third preset command is executed, 113 is performed. The fourth preset command is executed 114. Before the host receives the information of the SCSI device returned by the USB device, the host loads the corresponding SCSI driver, and the USB device establishes communication with the host, waiting to receive the SCSI driver. command.
  • the second SCSI command is a device information instruction (Inquiry command) for querying device information; specifically, when the value of the CBWCB field of the Inquiry command is the first preset content, the second SCSI command is the first
  • the third preset command when the value of the CBWCB field of the Inquiry command is the second preset content, the second SCSI command is the fourth preset command; wherein, the CBWCB domain is a command executed by the device, and is interpreted by the device;
  • the first preset content is: 12 00 00 00 24 00; wherein, the second preset content is: 12 01 80 00 ff 00 ; specifically, the third preset command is 55 53 42 43 bO ffi 82 91 ff 00 00 00 80 00 06 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  • the USB device determines that the host operating system is the second operating system, and sets the current operating system identifier to the second preset identifier, and executes 116.
  • the second operating system is Windows 7.
  • the USB device determines that the host operating system is the third operating system, and sets the current operating system identifier as the third preset identifier, and executes 116.
  • the third operating system is Windows Vista.
  • the USB device waits to receive an instruction sent by the HID driver.
  • the USB device determines whether the current operating system identifier is consistent with the default operating system identifier, if not, perform 117, otherwise, execute 118; 117.
  • the USB device performs soft power-down processing, and sets the power-on flag to the second preset value, and returns to 102.
  • Vcc power supply voltage or The pull-up resistor state of the operating voltage
  • the USB device has a pull-up resistor integrated in it. By default, it is not connected to Vcc.
  • the USB device When the USB device establishes a connection with the host, the internal device of the USB device The pull-up resistor is connected to Vcc, so that the host can detect whether there is a USB device connected by detecting the change of the pull-up resistor on Vcc.
  • the soft power-down processing specifically means: the USB device disconnects the internal pull-up resistor from Vcc. Connect, in this way, the host operating system will monitor that the USB device is unplugged, but the USB device is connected to Vcc, and the power can still be obtained from Vcc. The USB device is still in the power-on state, after the scheduled time is disconnected.
  • the pull-up resistor inside the USB device will be connected to Vcc again, the host operating system will monitor the insertion of the USB device again, and start the enumeration again. Operation, that is, the USB device returns to execution 102; here, the purpose of performing soft power-down processing is: According to the above process, before determining the specific operating system, the USB device has completed USB enumeration, and is according to the default operating system identifier. Returned device information (device type, etc.), this will cause an error.
  • the default operating system is the second operating system, that is, Windows 7, the device type returned during the enumeration process is SCSI device, but it is judged When the operating system is Windows XP, the device type that should be returned to the host is actually the CCID device. However, the SCSI device is returned according to the default operating system identifier. Therefore, a soft power failure is required, and the modified operating system identifier is newly performed. Enumeration, returns the correct device information, and identifies the correct operating system type for the host.
  • Embodiment 2 This embodiment provides a method for the USB device to identify the version of the host Windows operating system.
  • the Windows operating system type is divided according to the kernel to Windows XP Windows Vista. , Windows 7 for the representative to explain. See Figure 2, the specific method is as follows:
  • the USB device is powered on and initialized. Specifically, the USB device is connected to the host through the USB bus, and obtains a working voltage from the host Vcc (power supply voltage or working voltage); the initialization operation specifically includes: the USB device identifies the device type Initialize to the default identifier; It should be noted that the host operating system constantly monitors whether there is device access on the USB bus, specifically by detecting a change in the Vcc pull-up resistor. When the host detects that the USB device is connected, the device bus driver is loaded, and the operation is started. The USB device performs an enumeration operation.
  • Vcc power supply voltage or working voltage
  • USB device bus reset It should be noted that after the USB device bus is reset, the default address 0 of the USB device is enabled, and then the USB device and the host transmit the command and data through the address 0.
  • the USB device receives a series of setup packages delivered by the host, and completes the USB enumeration according to the default device type.
  • the USB device receives a series of setup packets sent by the host, including "fetch device descriptor”, “set device address”, “take configuration descriptor”, “take endpoint descriptor”, “take interface descriptor”, and “take”
  • the endpoint descriptor "" selects the configuration", etc., the USB device responds to it one by one, completing the USB enumeration. It should be noted that, in the enumeration phase, after receiving the "fetch device descriptor" command sent by the host, the USB device returns the default device type identifier to the host, and informs the host of its own device type.
  • the USB device determines whether there is a first preset command in the USB enumeration process. If yes, execute 205. Otherwise, execute 206.
  • the first preset command is a configuration descriptor command. Specifically, the configuration description is taken. The command is: 80 06 00 02 00 00 09 00.
  • the USB device determines that the host operating system is the first operating system, establishes communication with the host, and waits to receive an instruction sent by the first operating system of the host, and returns corresponding data; specifically, the first operating system of the host is loaded according to the default device type.
  • the corresponding driver establishes communication with the USB device and waits to receive an instruction issued by the first operating system of the host; specifically, the first operating system is Windows XP.
  • the USB device determines which device type identifier is the CCID device, the SCSI device, and the HID device, if it is a CCID device, perform 207; if it is a SCSI device, execute 210; If it is a HID device, execute 213; the device type identifier identifies that the device type is pre-agreed, and the USB device can determine the device type according to the pre-agreed device type identifier. For example, the device type identifier 0 identifies the CCID device, and the device Type 1 identifies the SCSI device and device type 2 identifies the HID device. 207.
  • the USB device receives the CCID command sent by the host CCID driver, and determines whether there is a second preset command in the received command. If not, execute 208, if yes, execute 209; before the host receives the USB After the device returns the information of the CCID device itself, the corresponding CCID driver is loaded, and the USB device establishes communication with the host, waiting to receive the command issued by the CCID driver.
  • the second preset command is a device status command; specifically, the device status command is 80 00 00 00 00 00 00 02 00.
  • the USB device determines that the host operating system is the third operating system, and waits to receive an instruction issued by the third operating system of the host, and returns corresponding data.
  • the third operating system is Windows Vista.
  • the USB device determines that the host operating system is the second operating system, and waits to receive an instruction sent by the second operating system of the host, and returns corresponding data; specifically, the second operating system is Windows 7.
  • the USB device receives the SCSI command sent by the SCSI driver, and determines whether the received second SCSI command is a third preset command or a fourth preset command. If it is a third preset command, executing 211, if yes The fourth preset command is executed 212. Before the host receives the information of the SCSI device returned by the USB device, the host loads the corresponding SCSI driver, and the USB device establishes communication with the host, waiting to receive the SCSI driver. command.
  • the second SCSI command is a device information instruction (Inquiry command) for querying device information; specifically, when the value of the CBWCB field of the Inquiry command is the first preset content, the second SCSI command is the first
  • the third preset command when the value of the CBWCB field of the Inquiry command is the second preset content, the second SCSI command is the fourth preset command; wherein, the CBWCB domain is a command executed by the device, and is interpreted by the device;
  • the first preset content is: 12 00 00 00 24 00; wherein, the second preset content is: 12 01 80 00 ff 00 ; specifically, the third preset command is 55 53 42 43 b0 ffi 82 91 ff 00 00 00 80 00 06 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  • the USB device determines that the host operating system is the second operating system, and waits to receive an instruction sent by the second operating system of the host, and returns corresponding data.
  • the second operating system is Windows 7.
  • the USB device determines that the host operating system is the third operating system, and waits to receive an instruction issued by the third operating system of the host, and returns corresponding data; specifically, the third operating system is Windows Vista.
  • the USB device waits to receive the command sent by the HID driver. It should be noted that when the USB device receives the instruction of reading the content of the CD delivered by the host operating system, the USB device will be based on the type of the operating system identified. Returning different data to the host, after determining the first, second, and third operating systems by the SCSI device, receiving a standard SCSI command issued by the host to read the contents of the optical disc, specifically: 55 53 42 43 b0 94 fD 85 00 08 00 00 080 00 0a 28 00 00 00 00 00 11 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00; When the SCSI device determines that the host is the first operating system, the data returned is: 02 43 44 30 30 31 01 00 00 57 00 69 00 6e 00 33 00 32 00 20 00 20 00 20 00 20 00 20
  • the Windows operating system type is divided according to the kernel, and is represented by Windows XP, Windows Vista, and Windows 7.
  • the specific method is as follows: Before the specific description, it is necessary to know that the USB device internally stores a mapping table of the operating system identifier and the device type identifier, and the mapping table is preset.
  • the first preset identifier is mapped to the first device identifier
  • the second preset identifier is mapped to the second device identifier
  • the third preset identifier is mapped to the third device identifier.
  • the first preset identifier is corresponding to the first preset identifier.
  • the first operating system, the second preset identifier corresponds to the second operating system, and the third preset identifier corresponds to the third operating system; the first device identifier corresponds to the CCID device, the second device identifier corresponds to the SCSI device, and the third device identifier corresponds to the HID device .
  • the USB device is powered on and initialized. Specifically, the USB device is connected to the host through the USB bus, and obtains a working voltage from the host Vcc (power supply voltage or working voltage).
  • the initialization operation specifically includes: the USB device will be powered on.
  • the device type identifier is initialized to a default identifier. Specifically, the power-on identifier is initialized to a first preset value, and the default device type identifier may be one of the first device identifier, the second device identifier, or the third device identifier.
  • the host operating system constantly monitors whether there is device access on the USB bus, specifically by detecting the change of the Vcc pull-up resistor. When the host detects that the USB device is connected, the device bus driver is loaded, and the USB device is started. Perform an enumeration operation.
  • USB device bus reset It should be noted that after the USB device bus is reset, the default address 0 of the USB device is enabled, and then the USB device and the host transmit the command and data through the address 0.
  • the USB device determines whether it is powered on for the first time. If not, execute 304. If yes, execute 305. Determine whether the USB device is powered on for the first time. Specifically, determine whether the power-on identification bit is the first preset value. , the USB device is powered on for the first time, otherwise, it is not powered on for the first time;
  • the USB device completes the enumeration according to the current device type identifier, and establishes communication with the host, and waits for receiving an instruction sent by the host;
  • the USB device receives a series of setup packages sent by the host, and completes the USB enumeration.
  • the USB device receives a series of setup packets sent by the host, including "fetch device descriptor”, “set device address”, “take configuration descriptor”, “take endpoint descriptor”, “take string descriptor”, Take the endpoint descriptor "" select configuration” and other commands, the USB device responds to them one by one;
  • the USB device determines whether the first preset command exists in the USB enumeration process. If yes, execute 307. If not, execute 308.
  • the first preset command is a configuration descriptor command; specifically, The configuration descriptor command is: 80 06 00 02 00 00 09 00.
  • the USB device determines that the host operating system is the first operating system, and sets the device type identifier to the first device identifier, and executes 316; specifically, the first operating system is Windows XP;
  • the USB device determines, according to the device type identifier, which device is the CCID device, the SCSI device, and the HID device. If it is a CCID device, execute 309; if it is a SCSI device, execute 312; if it is a HID device, execute 315;
  • the USB device receives the CCID command sent by the host CCID driver, and determines whether there is a second preset command in the received command. If not, execute 310, if yes, execute 311; before, the host receives the USB. After the device returns the information of the CCID device itself, the corresponding CCID driver is loaded, and the USB device establishes communication with the host, waiting to receive the command issued by the CCID driver.
  • the second preset command is a device status command; specifically, the device status command is 80 00 00 00 00 00 02 00.
  • the USB device determines that the host operating system is the third operating system, and sets the current device type identifier to the third device identifier, and executes 316.
  • the third operating system is Windows Vista. 311.
  • the USB device determines that the host operating system is the second operating system, and sets the current device type identifier to the second device identifier, and executes 316.
  • the second operating system is Windows 7.
  • the USB device receives the SCSI command sent by the SCSI driver, and determines whether the received second SCSI command is a third preset command or a fourth preset command. If the third preset command is executed, perform 313, if yes, The fourth preset command is executed 314. Before the host receives the information of the SCSI device returned by the USB device, the host loads the corresponding SCSI driver, and the USB device establishes communication with the host, waiting to receive the SCSI driver. command.
  • the second SCSI command is a device information instruction (Inquiry command) for querying device information; specifically, when the value of the CBWCB field (command field) of the Inquiry command is the first preset content, the second The SCSI command is a third preset command.
  • the second SCSI command is the fourth preset command; wherein the content of the CBWCB domain is identified by the device.
  • the first preset content is: 12 00 00 00 24 00; wherein, the second preset content is: 12 01 80 00 ff 00 ; specifically, the third preset command is 55 53 42 43 bO ffi 82 91 ff 00 00 00 80 00 06 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  • the USB device determines that the host operating system is the third operating system, and sets the current device type identifier to the third device identifier, and executes 316. Specifically, the third operating system is Windows Vista. 315. The USB device waits to receive an instruction sent by the HID driver.
  • the USB device determines whether the current device type identifier is consistent with the default device type identifier, if not, execute 317, otherwise, execute 318;
  • the USB device performs soft power-down processing, and sets the power-on identifier to a second preset value, and returns to 302.
  • the description of the soft power-down and the specific processing manner are detailed in step 116, where I won't go into details.
  • the purpose of the soft power-down processing is as follows: It is known from the above process that the USB device has completed the USB enumeration before determining the specific operating system, and is the device information (device type, etc.) returned according to the default device type identifier. This will cause an error. For example, in the enumeration phase, the default device type is returned to the host.
  • the device type is a SCSI device.
  • the device type that should actually be returned to the host is The CCID device, however, returns the SCSI device according to the default device type identifier. Therefore, it needs to be softly powered down, re-enumerate according to the modified device type identifier, and return the correct device information, that is, switch the device type to the determined device.
  • the correct device type for the operating system is the correct device type for the operating system.
  • the USB device continues to communicate with the host.
  • the USB device can determine the host by analyzing the instructions sent by the host.
  • the version type of the Windows operating system the determination method does not require additional equipment and software, is simple, convenient, and fast, and after determining the version type of the host Windows operating system, exposes different USB attributes to different host operating systems, in addition, USB
  • the device can implement the switching of the operating system type or the switching of the device type by setting the operating system identifier or the device type identifier, so as to better work with the host operating system.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)

Description

USB设备识别主机 Windows操作系统版本类型的方法 技术领域 本发明涉及计算机操作系统领域, 具体来说, 涉及一种 USB 设备识别主机 Windows操作系统版本类型的方法。 背景技术
USB协议技术是主机与外部设备连接的串行总线标准, 在主机 (例如, 个人计算 机、 个人数字助理以及移动电脑等) 上使用十分广泛, 支持热插拔和即插即用, 并支 持总线供电, 鼠标、 键盘、 游戏手柄、 扫描仪、 数码相机、 打印机、 硬盘、 安全设备、 光驱和网卡等几乎所有的外围设备都可以通过运行 USB接口与主机相连并进行通信, USB接口已经成为目前大多数主机外设与计算机相连的缺省接口。 在某些情况下, 设备可能必须知道它所连接的主机计算机上运行的操作系统的类 型, 但是, 现有技术中, 设备却是无法识别主机操作系统的。 发明内容 本发明提供了一种 USB设备识别主机 Windows操作系统版本类型的方法, 具体 技术方案如下: 一种 USB设备识别主机 Windows操作系统版本类型的方法, 所述方法包括: 步骤 A、 USB设备上电, 并进行初始化; 步骤 B、 所述 USB设备进行 USB枚举, 并判断所述 USB枚举过程中是否接收到 第一预设命令, 如果是, 则判定主机操作系统为第一操作系统, 执行步骤 D, 否则, 执行步骤 C; 步骤 C、 所述 USB设备判断所述 USB枚举过程中向主机返回的设备类型, 当所述 USB设备向所述主机返回的设备类型是 CCID设备时, 所述 USB设备判 断接收到的指令中是否存在第二预设命令, 如果存在所述第二预设命令, 则判定主机 操作系统为第二操作系统, 如果不存在所述第二预设命令, 则判定主机操作系统为第 三操作系统; 当所述 USB设备向所述主机返回的设备类型是 SCSI设备时,所述 USB设备接收 所述主机下发的 SCSI指令, 并判断接收到的所述第二条 SCSI指令是第三预设命令还 是第四预设命令, 如果是所述第三预设命令, 则判定主机操作系统为第二操作系统, 如果是所述第四预设命令, 则判定主机操作系统为第三操作系统; 步骤 D、 所述 USB设备与主机建立通信, 并等待接收所述主机下发的指令, 根据 所述判定出的主机操作系统类型向所述主机返回相应的信息。 所述初始化包括: 将设备类型标识初始化为默认设备类型标识。 所述初始化还包括: 将上电标识初始化为第一预设值、 设备类型标识初始化为默 认设备类型标识。 所述 USB设备判断所述 USB枚举过程中向主机返回的设备类型为:所述 USB设 备根据所述 USB枚举过程中返回的设备类型标识来判断所述返回的设备类型。 所述方法还包括: 所述 USB设备判定出主机操作系统类型是第一操作系统、第二 操作系统或第三操作系统后, 将设备类型标识置为第一设备类型、 第二设备类型或第 三设备类型。 所述步骤 D还包括: 所述 USB设备判断当前设备类型标识是否与默认设备类型 标识相同, 如果相同, 则所述 USB设备与主机通信, 等待接收所述主机下发的指令; 如果不相同, 所述 USB设备进行软掉电处理, 并将所述上电标识置为第二预设值, 执 行步骤 A。 所述初始化还包括: 将上电标识初始化为第一预设值, 将操作系统类型标识初始 化为默认操作系统类型标识。 所述方法还包括:所述 USB设备存储有操作系统类型标识与设备类型标识的映射 表。 所述 USB设备判断所述 USB枚举过程中返回的设备类型为:所述 USB设备根据 默认操作系统类型标识查找所述映射表得到相应的设备类型标识, 根据所述查找所得 的设备类型标识来判断所述返回的设备类型。 所述方法还包括: 所述 USB设备判定出主机操作系统类型是第一操作系统、第二 操作系统或第三操作系统后, 将操作系统类型标识置为第一预设标识、 第二预设标识 或第三预设标识。 所述步骤 D还包括: 所述 USB设备判断当前操作系统类型标识是否与所述默认 操作系统类型标识相同, 如果相同, 则所述 USB设备与主机建立通信, 并等待接收所 述主机下发的指令; 如果不相同, 所述 USB设备进行软掉电处理, 并将所述上电标识 置为第二预设值, 执行步骤 。 在所述步骤 A之后, 所述方法还包括: 判断所述 USB设备是否是首次上电, 如 果是首次上电, 则执行步骤 B; 如果不是, 所述 USB设备执行步骤 D。 判断所述 USB设备是否是首次上电具体为: 判断上电标识是否是第一预设值, 如 果是, 则所述 USB设备是首次上电, 如果不是, 则所述 USB设备不是首次上电。 所述 USB设备向所述主机返回的设备类型还包括 HID设备。 所述第一预设命令为取设备配置描述符命令; 所述第二预设命令为取设备状态指 令; 所述第二条 SCSI指令为取设备信息指令。 所述 USB设备判断接收到的第二条 SCSI指令是第三预设命令还是第四预设命令 为: 所述 USB设备根据所述第二条 SCSI指令的命令域的内容进行判断, 当所述第二 条 SCSI指令的命令域内容是第一预设内容时, 所述第二条指令是所述第三预设命令; 当所述第二条 SCSI指令的命令域内容是第二预设内容时, 所述第二条指令是所述第 四预设命令。 所述第一操作系统为 Windows XP, 所述第二操作系统为 Windows 7, 所述第三操 作系统为 Windows Vista。 有益效果: USB 设备通过分析接收到的由主机下发的指令, 便可以确定主机 Windows操作系统版本类型, 并在确定主机 Windows操作系统版本类型后, 向不同版 本的主机操作系统暴露不同的 USB属性, 以便更好的和主机操作系统配合工作。 附图说明 图 1为本发明实施例 1提供的一种 USB设备识别主机 Windows操作系统版本类 型的方法流程图; 图 2为本发明实施例 2提供的一种 USB设备识别主机 Windows操作系统版本类 型的方法流程图; 图 3为本发明实施例 3提供的一种 USB设备识别主机 Windows操作系统版本类 型的方法流程图。 具体实施方式 为使本发明的目的、 技术方案和优点更加清楚, 下面将结合附图对本发明实施方 式作进一步地详细描述。 在进行具体说明之前,对 USB设备与主机之间的通信原理进行简单的说明,如下:
USB设备与主机之间的通信是: 由主机发送命令给 USB设备, USB设备对接收 到的命令进行响应, USB设备与主机之间通信的基本单位是"包", 其中, "包"的分类 主要有: 令牌包、 数据包和握手包, 由 PID来决定包的具体类型。 其中, 令牌包的格式为 SYNC+PID+ADDR+E DP+CRC; 数据包分为 DATA0包 和 DATA1包, 在 USB设备返回的数据长度超过相应端点的最大输出数据包长度时, 需要将返回的数据分批发送, 一般情况下, DATA0包和 DATA1包交替发送; 握手包 的格式为: SYNC+PID。 其中, USB设备与主机之间通过设备端点来进行数据的收发。 例如:
PID: SETUP ADDR:00 E DP:00 CRC5:02 idle:3
PID:DATA0 data: 80 06 00 01 00 00 40 00 CRC16:94dd idle:7
PID:ACK idle:2ela 上述命令说明, 该包为 SETUP包, 数据内容是 80 06 00 01 00 00 40 00, 握手包为 ACK; 其中, SETUP包由主机下发, USB设备接收到该 SETUP包后向主机返回应答信 息, 例如:
PID:IN ADDR:00 E DP:00 CRC5:02 idle:7
PID:DATA1 data: 12 01 10 01 00 00 00 08 CRC16:7711 idle:7
PID:ACK idle:2el6
PID UT ADDR:00 E DP:00 CRC5:02 idle:3 PID:DATA1 data: CRC 16:0000 idle:7 PID:ACK idle:2e5a
USB设备向主机返回的应答数据是 12 01 10 01 00 00 00 08, 需要说明的是, USB 设备在接收到主机下发的 IN或 OUT的令牌包后, 向主机返回应答数据; 这样, USB设备与主机之间便完成了一次信息交互, 而每一次的信息交互, 都是 由接收到主机下发的 SETUP包开始的。 另外, 还需要说明的是, 根据 USB设备与主机间进行数据通信时采用的通信协议 (CCID、 SCSI或 HID协议) 的不同, USB设备又可以分为 CCID设备、 SCSI设备和 HID设备。 实施例 1 本实施例提供了一种 USB 设备识别主机 Windows 操作系统版本类型的方法, Windows操作系统版本类型是根据内核的不同进行划分的, 以 Windows XP、 Windows Vista、 Windows 7为代表进行说明。 参见图 1, 具体方法如下:
101、 USB设备上电, 并进行初始化; 其中, USB设备具体包括: 安全设备 (如 USB Key)、 读卡器等; 具体地, USB设备通过 USB总线连接到主机, 并从主机 Vcc (电源电压或工作电 压) 处获取工作电压; 初始化操作具体包括: USB设备将自身存储的上电标识、 操作系统标识初始化为 默认标识; 具体地, 默认上电标识为第一预设值, 默认操作系统标识可以是第一预设标识、 第二预设标识或第三预设标识中的一个; 其中, 第一预设标识对应第一操作系统、 第二预设标识对应第二操作系统、 第三 预设标识对应第三操作系统; 需要说明的是, 主机操作系统时刻监测 USB总线上是否有设备接入, 具体是通过 检测 Vcc上拉电阻的变化来确定的,并在检测到 USB设备接入时,加载设备总线驱动, 开始对 USB设备进行枚举操作, 具体如 102至 106所示。 102、 USB设备总线复位; 需要说明的是, USB设备总线复位后, 该 USB设备的默认地址 0被使能, 接下 来, USB设备与主机之间通过地址 0来传输命令及数据。
103、 USB 设备判断自身是否是首次上电, 如果不是, 执行 104; 如果是, 执行 105; 判断 USB设备是否是首次上电具体为:判断上电标识是否为第一预设值,如果是, 则 USB设备为首次上电, 否则, 不是首次上电。
104、 USB 设备按照当前操作系统标识完成枚举, 并与主机建立通信, 等待接收 主机下发的指令; 105、 USB设备接收主机下发的一系列 setup包, 按照默认操作系统标识完成 USB 枚举; 具体地,默认操作系统标识所对应的主机操作系统向 USB设备下发一系列的 setup 包, 对 USB设备进行枚举, 以获取 USB设备的描述信息;
USB设备接收主机下发的一系列 setup包, 包括"取设备描述符"、 " 设置设备地 址"、 " 取配置描述符"、 " 取端点描述符"、 "取字符串描述符"、 "取端点描述符"" 选 择配置 "等命令, USB设备逐一对其做出响应。
106、 USB设备判断 USB枚举过程中是否存在第一预设命令,如果存在,执行 107; 如果不存在, 执行 108; 具体地, 第一预设命令为取配置描述符命令; 具体地, 取配置描述符命令为: 80 06 00 02 00 00 09 00。
107、 USB 设备认定主机操作系统是第一操作系统, 并将操作系统标识置为第一 预设标识, 执行 116; 具体地, 第一操作系统是 Windows XP;
108、 USB设备根据默认操作系统标识来判断 USB枚举过程中返回的设备类型是 CCID设备、 SCSI设备和 HID设备的哪一种, 如果是 CCID设备, 执行 109; 如果是 SCSI设备, 执行 112; 如果是 HID设备, 执行 115; 具体地,在 USB枚举过程中, USB设备接收到主机下发的"取设备描述符 "信息后, 在操作系统标识与设备类型标识的映射表中, 查找操作系统标识所对应的设备类型, 并将查找所得的设备类型返回给主机。 其中, 操作系统标识与设备类型标识的映射表是预先设定, 并存储在 USB设备中 的; 这样, USB设备在判断返回的设备类型时, 就可以通过操作系统标识与设备类型 标识的映射表, 根据操作系统标识来确认设备类型了; 例如, 第一预设标识映射 CCID设备标识、第二预设标识映射 SCSI设备标识、第 三预设标识映射 HID设备标识, 贝 1」, 当操作系统标识是第一预设标识时, USB设备便 根据该标识知道返回的设备类型是 CCID设备。
109、 USB设备接收主机 CCID驱动程序下发的 CCID命令, 并判断接收到的命令 中是否存在第二预设命令, 如果不存在, 执行 110, 如果存在, 执行 111 ; 之前, 主机在接收到 USB设备返回的自身是 CCID设备的信息后, 装载相应的
CCID驱动, USB设备与主机之间建立通信, 等待接收 CCID驱动程序下发的命令。 具体地, 第二预设命令是取设备状态命令; 具体地, 取设备状态命令是 80 00 00 00 00 00 02 00。
110、 USB 设备认定主机操作系统为第三操作系统, 并将当前操作系统标识置为 第三预设标识, 执行 116; 具体地, 第三操作系统是 Windows Vista。
111、 USB 设备认定主机操作系统是第二操作系统, 并将当前操作系统标识置为 第二预设标识, 执行 116; 具体地, 第二操作系统是 Windows 7。 112、 USB设备接收 SCSI驱动程序下发的 SCSI指令,并判断接收到的第二条 SCSI 指令是第三预设命令还是第四预设命令, 如果是第三预设命令, 执行 113, 如果是第 四预设命令, 执行 114; 之前,主机在接收到 USB设备返回的自身是 SCSI设备的信息后,装载相应的 SCSI 驱动, USB设备与主机之间建立通信, 等待接收 SCSI驱动程序下发的命令。 具体地,第二条 SCSI指令是取设备信息指令(Inquiry指令),用于查询设备信息; 具体地, 当 Inquiry指令的 CBWCB域的数值是第一预设内容时, 第二条 SCSI指 令是第三预设命令, 当 Inquiry指令的 CBWCB域的数值是第二预设内容时, 第二条 SCSI指令是第四预设命令; 其中, CBWCB域是由设备执行的命令, 由设备解释; 其中, 第一预设内容为: 12 00 00 00 24 00; 其中, 第二预设内容为: 12 01 80 00 ff 00 ; 具体地,第三预设命令为 55 53 42 43 bO ffi 82 91 ff 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00; 具体地, 第四预设命令为 55 53 42 43 bO ffi 82 91 ff 00 00 00 80 00 06 12 01 80 00 ff
00 00 00 00 00 00 00 00 00 00 00。
113、 USB 设备认定主机操作系统是第二操作系统, 并将当前操作系统标识置为 第二预设标识, 执行 116 具体地, 第二操作系统是 Windows 7。 114、 USB 设备认定主机操作系统是第三操作系统, 并将当前操作系标识置为第 三预设标识, 执行 116; 具体地, 第三操作系统是 Windows Vista。
115、 USB设备等待接收 HID驱动程序下发的指令;
116、 USB 设备判断当前操作系统标识是否与默认操作系统标识一致, 如果不一 致, 执行 117, 否则, 执行 118; 117、 USB设备进行软掉电处理, 并将上电标识置为第二预设值, 返回 102; 在对软掉电处理进行说明之前, 需要知道是, USB设备通过改变主机 Vcc (电源 电压或工作电压) 的上拉电阻状态来告知主机自身的插拔状态, USB设备内部集成有 上拉电阻, 默认状态下是不与 Vcc相连的, 当 USB设备与主机建立连接时, USB设 备内部的上拉电阻连接到 Vcc上, 这样主机便可以通过检测 Vcc上的上拉电阻的变化 来确定是否有 USB设备连入了; 软掉电处理具体是指: USB设备断开内部上拉电阻与 Vcc的连接, 这样, 主机操 作系统将会监控到 USB设备是拔出状态, 但 USB设备是与 Vcc相连的, 依然可以从 Vcc处获取电源, USB设备依然是处于上电状态的, 断开预定时间后 (极短的时间), USB设备内部的上拉电阻将再次连到 Vcc,主机操作系统将再次监控到 USB设备的插 入, 重新开始进行枚举操作, 即 USB设备返回执行 102; 这里, 进行软掉电处理的目的是: 由上述流程知道, 在判断出具体的操作系统之 前, USB设备已经完成了 USB枚举, 并且是按照默认操作系统标识返回的设备信息 (设备类型等), 这样就会错误产生, 如, 默认操作系统是第二操作系统, 即 Windows 7,则在枚举过程中返回的设备类型为 SCSI设备,但是,在判断出操作系统是 Windows XP时, 实际上应该向主机返回的设备类型是 CCID设备, 但是, 却按默认操作系统标 识返回了 SCSI设备, 所以, 需要进行软掉电, 按照已修改的操作系统标识从新进行 枚举, 返回正确的设备信息, 并且标识了主机正确的操作系统类型。
118、 USB设备继续与主机进行通信; 实施例 2 本实施例提供了一种 USB 设备识别主机 Windows 操作系统版本类型的方法, Windows操作系统类型是根据内核的不同进行划分的,以 Windows XP Windows Vista、 Windows 7为代表进行说明。 参见图 2, 具体方法如下:
201、 USB设备上电, 并进行初始化; 具体地, USB设备通过 USB总线连接到主机, 并从主机 Vcc (电源电压或工作电 压) 处获取工作电压; 初始化操作具体包括: USB设备将设备类型标识初始化为默认标识; 需要说明的是, 主机操作系统时刻监测 USB总线上是否有设备接入, 具体是通过 检测 Vcc上拉电阻的变化来确定的, 当主机检测到 USB设备接入时,加载设备总线驱 动, 开始对 USB设备进行枚举操作。
202、 USB设备总线复位; 需要说明的是, USB设备总线复位后, 该 USB设备的默认地址 0被使能, 则接 下来 USB设备与主机之间便通过地址 0来传输命令及数据。
203、 USB设备接收主机下发的一系列 setup包, 按照默认设备类型完成 USB枚 举。
USB设备接收主机下发的一系列 setup包, 具体包括"取设备描述符"、 " 设置设 备地址"、 " 取配置描述符"、 " 取端点描述符"、 "取接口描述符"、 "取端点描述符"" 选 择配置 "等, USB设备逐一对其做出响应, 完成 USB枚举。 需要说明的是, USB设备在枚举阶段,接收到主机下发的"取设备描述符 "命令后, 将默认设备类型标识返回给主机, 告知主机自身的设备类型。
204、 USB设备判断 USB枚举过程中是否存在第一预设命令,如果存在,执行 205, 否则, 执行 206; 具体地, 第一预设命令为取配置描述符命令; 具体地, 取配置描述符命令为: 80 06 00 02 00 00 09 00。
205、 USB 设备认定主机操作系统是第一操作系统, 与主机建立通信, 并等待接 收主机第一操作系统下发的指令, 返回相应的数据; 具体地, 主机第一操作系统按照默认设备类型加载相应的驱动, 与 USB设备建立 通信, 等待接收主机第一操作系统下发的指令; 具体地, 第一操作系统为 Windows XP。
206、 USB设备判断默认设备类型标识是 CCID设备、 SCSI设备和 HID设备的哪 一种, 如果是 CCID设备, 执行 207; 如果是 SCSI设备, 执行 210; 如果是 HID设备, 执行 213 ; 设备类型标识标识了那种设备类型是预先约定的, USB设备根据预先约定的设备 类型标识就可以判断出设备类型, 例如, 设备类型标识 0标识了 CCID设备, 设备类 型 1标识了 SCSI设备, 设备类型 2标识了 HID设备。 207、 USB设备接收主机 CCID驱动程序下发的 CCID命令, 并判断接收到的命令 中是否存在第二预设命令, 如果不存在, 执行 208, 如果存在, 执行 209; 之前, 主机在接收到 USB设备返回的自身是 CCID设备的信息后, 装载相应的 CCID驱动, USB设备与主机之间建立通信, 等待接收 CCID驱动程序下发的命令。 具体地, 第二预设命令是取设备状态命令; 具体地, 取设备状态命令是 80 00 00 00 00 00 02 00。
208、 USB 设备认定主机操作系统为第三操作系统, 等待接收主机第三操作系统 下发的指令, 返回相应的数据; 具体地, 第三操作系统是 Windows Vista。
209、 USB 设备认定主机操作系统是第二操作系统, 等待接收主机第二操作系统 下发的指令, 返回相应的数据; 具体地, 第二操作系统是 Windows 7。
210、 USB设备接收 SCSI驱动程序下发的 SCSI指令,并判断接收到的第二条 SCSI 指令是第三预设命令还是第四预设命令, 如果是第三预设命令, 执行 211, 如果是第 四预设命令, 执行 212; 之前,主机在接收到 USB设备返回的自身是 SCSI设备的信息后,装载相应的 SCSI 驱动, USB设备与主机之间建立通信, 等待接收 SCSI驱动程序下发的命令。 具体地,第二条 SCSI指令是取设备信息指令(Inquiry指令),用于查询设备信息; 具体地, 当 Inquiry指令的 CBWCB域的数值是第一预设内容时, 第二条 SCSI指 令是第三预设命令, 当 Inquiry指令的 CBWCB域的数值是第二预设内容时, 第二条 SCSI指令是第四预设命令; 其中, CBWCB域是由设备执行的命令, 由设备解释; 其中, 第一预设内容为: 12 00 00 00 24 00; 其中, 第二预设内容为: 12 01 80 00 ff 00 ; 具体地,第三预设命令为 55 53 42 43 b0 ffi 82 91 ff 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00; 具体地, 第四预设命令为 55 53 42 43 b0 ffi 82 91 ff 00 00 00 80 00 06 12 01 80 00 ff
00 00 00 00 00 00 00 00 00 00 00。
211、 USB 设备认定主机操作系统是第二操作系统, 等待接收主机第二操作系统 下发的指令, 返回相应的数据; 具体地, 第二操作系统是 Windows 7。 212、 USB 设备认定主机操作系统是第三操作系统, 等待接收主机第三操作系统 下发的指令, 返回相应的数据; 具体地, 第三操作系统是 Windows Vista。
213、 USB设备等待接收 HID驱动程序下发的指令; 需要说明的是, USB设备在接收到主机操作系统下发的读取光盘内容的指令时, USB设备将会根据所认定的操作系统类型, 向主机返回不同的数据, 以 SCSI设备判 断第一、 第二、 第三操作系统后, 接收到主机下发的读取光盘内容的标准 SCSI指令, 具体为: 55 53 42 43 b0 94 fD 85 00 08 00 00 080 00 0a 28 00 00 00 00 11 00 00 01 00 00 00 00 00 00 00; SCSI设备在认定主机是第一操作系统时, 返回的数据为: 02 43 44 30 30 31 01 00 00 57 00 69 00 6e 00 33 00 32 00 20 00 20 00 20 00 20 00 20 00 20 00 20; SCSI设备在认定主机是第二操作系统时,返回的数据为: 00 43 44 30 30 31 01 00 00 57 00 69 00 6e 00 33 00 32 00 20 00 20 00 20 00 20 00 20 00 20 00 20;SCSI设备在认定主机 是第三操作系统时, 返回的数据为: 05 43 44 30 30 31 01 00 00 57 00 69 00 6e 00 33 00 32 00 20 00 20 00 20 00 20 00 20 00 20 00 20。 实施例 3 本实施例提供了一种 USB 设备识别主机 Windows 操作系统版本类型的方法,
Windows操作系统类型是根据内核的不同进行划分的,以 Windows XP Windows Vista、 Windows 7为代表进行说明。 参见图 3, 具体方法如下: 在进行具体说明之前, 需要知道的是, USB设备内部存储有操作系统标识与设备 类型标识的映射表, 该映射表是预先设定的。 本实施例中, 第一预设标识映射到第一 设备标识, 第二预设标识映射到第二设备标识, 第三预设标识映射到第三设备标识; 具体地, 第一预设标识对应第一操作系统, 第二预设标识对应第二操作系统, 第三预 设标识对应第三操作系统; 第一设备标识对应 CCID 设备, 第二设备标识对应 SCSI 设备, 第三设备标识对应 HID设备。
301、 USB设备上电, 并进行初始化; 具体地, USB设备通过 USB总线连接到主机, 并从主机 Vcc (电源电压或工作电 压) 处获取工作电压; 初始化操作具体包括: USB设备将上电标识、 设备类型标识初始化为默认标识; 具体地, 将上电标识初始化为第一预设值, 默认设备类型标识可以是第一设备标 识、 第二设备标识或第三设备标识中的一个; 需要说明的是, 主机操作系统时刻监测 USB总线上是否有设备接入, 具体是通过 检测 Vcc上拉电阻的变化来确定的, 当主机检测到 USB设备接入时,加载设备总线驱 动, 开始对 USB设备进行枚举操作。
302、 USB设备总线复位; 需要说明的是, USB设备总线复位后, 该 USB设备的默认地址 0被使能, 则接 下来 USB设备与主机之间便通过地址 0来传输命令及数据。
303、 USB 设备判断自身是否是首次上电, 如果不是, 执行 304, 如果是, 执行 305; 判断 USB设备是否是首次上电具体为: 判断上电标识位是否为第一预设值, 如果 是, 则 USB设备为首次上电, 否则, 不是首次上电;
304、 USB 设备按照当前设备类型标识完成枚举, 并与主机建立通信, 等待接收 主机下发的指令;
305、 USB设备接收主机下发的一系列 setup包, 完成 USB枚举; USB设备接收主机下发的一系列 setup包, 具体包括"取设备描述符"、 " 设置设 备地址"、 " 取配置描述符"、 " 取端点描述符"、 "取字符串描述符"、 "取端点描述符"" 选 择配置 "等命令, USB设备逐一对其做出响应;
306、 USB设备判断 USB枚举过程中是否存在第一预设命令,如果存在,执行 307, 如果不存在, 执行 308; 具体地, 第一预设命令为取配置描述符命令; 具体地, 取配置描述符命令为: 80 06 00 02 00 00 09 00。
307、 USB 设备认定主机操作系统是第一操作系统, 并将设备类型标识置为第一 设备标识, 执行 316; 具体地, 第一操作系统是 Windows XP;
308、 USB设备根据设备类型标识判断 USB设备是 CCID设备、 SCSI设备和 HID 设备的哪一种, 如果是 CCID设备, 执行 309; 如果是 SCSI设备, 执行 312; 如果是 HID设备, 执行 315;
309、 USB设备接收主机 CCID驱动程序下发的 CCID命令, 并判断接收到的命令 中是否存在第二预设命令, 如果不存在, 执行 310, 如果存在, 执行 311 ; 之前, 主机在接收到 USB设备返回的自身是 CCID设备的信息后, 装载相应的 CCID驱动, USB设备与主机之间建立通信, 等待接收 CCID驱动程序下发的命令。 具体地, 第二预设命令是取设备状态命令; 具体地, 取设备状态命令是 80 00 00 00 00 00 02 00。
310、 USB 设备认定主机操作系统为第三操作系统, 并将当前设备类型标识置为 第三设备标识, 执行 316; 具体地, 第三操作系统是 Windows Vista。 311、 USB 设备认定主机操作系统是第二操作系统, 并将当前设备类型标识置为 第二设备标识, 执行 316; 具体地, 第二操作系统是 Windows 7。
312、 USB设备接收 SCSI驱动程序下发的 SCSI指令,并判断接收到的第二条 SCSI 指令是第三预设命令还是第四预设命令, 如果是第三预设命令, 执行 313, 如果是第 四预设命令, 执行 314; 之前,主机在接收到 USB设备返回的自身是 SCSI设备的信息后,装载相应的 SCSI 驱动, USB设备与主机之间建立通信, 等待接收 SCSI驱动程序下发的命令。 具体地,第二条 SCSI指令是取设备信息指令(Inquiry指令),用于查询设备信息; 具体地, 当 Inquiry指令的 CBWCB域(命令域)的数值是第一预设内容时, 第二 条 SCSI指令是第三预设命令,当 Inquiry指令的 CBWCB域的数值是第二预设内容时, 第二条 SCSI指令是第四预设命令; 其中, CBWCB域的内容标识的是由设备所执行的命令, 由设备解释; 其中, 第一预设内容为: 12 00 00 00 24 00; 其中, 第二预设内容为: 12 01 80 00 ff 00 ; 具体地,第三预设命令为 55 53 42 43 bO ffi 82 91 ff 00 00 00 80 00 06 12 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00; 具体地, 第四预设命令为 55 53 42 43 bO ffi 82 91 ff 00 00 00 80 00 06 12 01 80 00 ff 00 00 00 00 00 00 00 00 00 00 00; 313、 USB 设备认定主机操作系统是第二操作系统, 并将当前设备类型标识置为 第二设备标识, 执行 316 具体地, 第二操作系统是 Windows 7;
314、 USB 设备认定主机操作系统是第三操作系统, 并将当前设备类型标识置为 第三设备标识, 执行 316; 具体地, 第三操作系统是 Windows Vista; 315、 USB设备等待接收 HID驱动程序下发的指令;
316、 USB 设备判断当前设备类型标识是否与默认设备类型标识一致, 如果不一 致, 执行 317, 否则, 执行 318;
317、 USB设备进行软掉电处理, 并将上电标识置为第二预设值, 返回 302; 这里, 有关软掉电的说明及具体的处理方式在步骤 116中有详细的说明, 此处就 不再赘述。 这里, 进行软掉电处理的目的是: 由上述流程知道, 在判断出具体的操作系统之 前, USB设备已经完成了 USB枚举, 并且是按照默认设备类型标识返回的设备信息 (设备类型等), 这样就会错误产生, 如, 在枚举阶段向主机返回默认的设备类型, 该 设备类型是 SCSI设备; 但是, 在判断出操作系统是 Windows XP时, 实际上应该向主 机返回的设备类型是 CCID设备, 但是, 却按默认设备类型标识返回了 SCSI设备, 所 以, 需要进行软掉电, 按照已修改的设备类型标识重新进行枚举, 返回正确的设备信 息, 即将设备类型切换为判断出的操作系统相对应的正确的设备类型。
318、 USB设备继续与主机进行通信。 上述实施例中, USB 设备通过对主机下发的指令进行分析, 便可以确定主机
Windows操作系统的版本类型, 该判定方法无需额外的设备及软件, 简单、 方便、 快 捷, 并在确定主机 Windows操作系统的版本类型后, 向不同的主机操作系统暴露不同 的 USB属性, 另外, USB设备通过设置操作系统标识符或设备类型标识符可以实现 操作系统类型的切换或设备类型的切换, 以便更好的和主机操作系统配合工作。 以上仅为本发明的较佳实施例, 并不用以限制本发明, 凡在本发明的精神和原则 之内, 所作的任何修改、 等同替换、 改进等, 均应包含在本发明的保护范围之内。

Claims

权 利 要 求 书
1. 一种 USB设备识别主机 Windows操作系统版本类型的方法, 其特征在于, 所 述方法包括:
步骤 A、 USB设备上电, 并进行初始化;
步骤 B、所述 USB设备进行 USB枚举, 并判断所述 USB枚举过程中是否 接收到第一预设命令, 如果是, 则判定主机操作系统为第一操作系统, 执行步 骤 D;否则, 执行步骤 C;
步骤 C、所述 USB设备判断所述 USB枚举过程中向主机返回的设备类型, 当所述 USB设备向所述主机返回的设备类型是 CCID设备时, 所述 USB 设备判断接收到的指令中是否存在第二预设命令,如果存在所述第二预设命令, 则判定主机操作系统为第二操作系统; 如果不存在所述第二预设命令, 则判定 主机操作系统为第三操作系统;
当所述 USB设备向所述主机返回的设备类型是 SCSI设备时, 所述 USB 设备接收所述主机下发的 SCSI指令, 并判断接收到的第二条 SCSI指令是第三 预设命令还是第四预设命令, 如果是所述第三预设命令, 则判定主机操作系统 为第二操作系统; 如果是所述第四预设命令, 则判定主机操作系统为第三操作 系统;
步骤 D、所述 USB设备与主机建立通信,并等待接收所述主机下发的指令, 根据所述判定出的主机操作系统类型向所述主机返回相应的信息。
2. 根据权利要求 1所述的方法, 其特征在于, 所述初始化包括: 将设备类型标识 初始化为默认设备类型标识。
3. 根据权利要求 1所述的方法, 其特征在于, 所述初始化还包括: 将上电标识初 始化为第一预设值、 设备类型标识初始化为默认设备类型标识。
4. 根据权利 2所述的方法, 其特征在于, 所述 USB设备判断所述 USB枚举过程 中向主机返回的设备类型为: 所述 USB设备根据所述 USB枚举过程中返回的 设备类型标识来判断所述返回的设备类型。
5. 根据权利 3所述的方法, 其特征在于, 所述 USB设备判断所述 USB枚举过程 中向主机返回的设备类型为: 所述 USB设备根据所述 USB枚举过程中返回的 设备类型标识来判断所述返回的设备类型。
6. 根据权利要求 3所述的方法, 其特征在于, 所述方法还包括: 所述 USB设备判 定出主机操作系统类型是第一操作系统、 第二操作系统或第三操作系统后, 将 设备类型标识置为第一设备类型、 第二设备类型或第三设备类型。
7. 根据权利要求 6所述的方法, 其特征在于, 所述步骤 D还包括: 所述 USB设 备判断当前设备类型标识是否与默认设备类型标识相同, 如果相同, 则所述 USB设备与主机通信, 等待接收所述主机下发的指令; 如果不相同, 所述 USB 设备进行软掉电处理, 并将所述上电标识置为第二预设值, 执行步骤 。
8. 根据权利要求 1所述的方法, 其特征在于, 所述初始化还包括: 将上电标识初 始化为第一预设值, 将操作系统类型标识初始化为默认操作系统类型标识。
9. 根据权利要求 8所述的方法, 其特征在于, 所述方法还包括: 所述 USB设备存 储有操作系统类型标识与设备类型标识的映射表。
10. 根据权利要求 9所述的方法, 其特征在于, 所述 USB设备判断所述 USB枚举 过程中返回的设备类型为:所述 USB设备根据默认操作系统类型标识查找所述 映射表得到相应的设备类型标识, 根据所述查找所得的设备类型标识来判断所 述返回的设备类型。
11. 根据权利要求 8所述的方法, 其特征在于, 所述方法还包括: 所述 USB设备判 定出主机操作系统类型是第一操作系统、 第二操作系统或第三操作系统后, 将 操作系统类型标识置为第一预设标识、 第二预设标识或第三预设标识。
12. 根据权利要求 11所述的方法, 其特征在于, 所述步骤 D还包括: 所述 USB设 备判断当前操作系统类型标识是否与所述默认操作系统类型标识相同, 如果相 同, 则所述 USB设备与主机建立通信, 并等待接收所述主机下发的指令; 如果 不相同, 所述 USB设备进行软掉电处理, 并将所述上电标识置为第二预设值, 执行步骤 A。
13. 根据权利要求 7所述的方法, 其特征在于, 在所述步骤 A之后, 所述方法还包 括: 判断所述 USB设备是否是首次上电, 如果是首次上电, 则执行步骤 B; 如 果不是, 所述 USB设备执行步骤 D。
14. 根据权利要求 12所述的方法, 其特征在于, 在所述步骤 A之后, 所述方法还 包括: 判断所述 USB设备是否是首次上电, 如果是首次上电, 则执行步骤 B; 如果不是, 所述 USB设备执行步骤 D。
15. 根据权利要求 13所述的方法, 其特征在于, 判断所述 USB设备是否是首次上 电具体为: 判断上电标识是否是第一预设值, 如果是, 则所述 USB设备是首次 上电; 如果不是, 则所述 USB设备不是首次上电。
16. 根据权利要求 1所述的方法,其特征在于,所述 USB设备向所述主机返回的设 备类型还包括 HID设备。
17. 根据权利要求 1所述的方法, 其特征在于, 所述第一预设命令为取设备配置描 述符命令; 所述第二预设命令为取设备状态指令; 所述第二条 SCSI指令为取 设备信息指令。
18. 根据权利要求 1所述的方法,其特征在于,所述 USB设备判断接收到的第二条 SCSI指令是第三预设命令还是第四预设命令为: 所述 USB设备根据所述第二 条 SCSI指令的命令域的内容进行判断, 当所述第二条 SCSI指令的命令域内容 是第一预设内容时, 所述第二条指令是所述第三预设命令; 当所述第二条 SCSI 指令的命令域内容是第二预设内容时, 所述第二条指令是所述第四预设命令。
19. 根据权利要求 1所述的方法, 其特征在于, 所述第一操作系统为 Windows XP, 所述第二操作系统为 Windows 7, 所述第三操作系统为 Windows Vista„
PCT/CN2011/079679 2010-09-16 2011-09-15 Usb设备识别主机windows操作系统版本类型的方法 WO2012034524A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US13/640,997 US8862790B2 (en) 2010-09-16 2011-09-15 Method for identifying version type of windows operating system on a host by a USB device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN 201010285447 CN101957807B (zh) 2010-09-16 2010-09-16 USB设备识别主机Windows操作系统版本类型的方法
CN201010285447.X 2010-09-16

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US13/640,997 Substitution US8862790B2 (en) 2010-09-16 2011-09-15 Method for identifying version type of windows operating system on a host by a USB device

Publications (1)

Publication Number Publication Date
WO2012034524A1 true WO2012034524A1 (zh) 2012-03-22

Family

ID=43485140

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/079679 WO2012034524A1 (zh) 2010-09-16 2011-09-15 Usb设备识别主机windows操作系统版本类型的方法

Country Status (3)

Country Link
US (1) US8862790B2 (zh)
CN (1) CN101957807B (zh)
WO (1) WO2012034524A1 (zh)

Families Citing this family (26)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101916238B (zh) * 2010-08-26 2012-01-25 华为终端有限公司 数据卡识别操作系统的方法、装置及通信系统
CN101957807B (zh) 2010-09-16 2012-08-08 飞天诚信科技股份有限公司 USB设备识别主机Windows操作系统版本类型的方法
CN102088797A (zh) * 2011-01-30 2011-06-08 中兴通讯股份有限公司 一种无线通讯方法、系统及无线通讯终端
CN102736982B (zh) * 2011-04-08 2015-04-22 群联电子股份有限公司 内存组态方法、内存控制器与内存储存装置
CN102253904A (zh) * 2011-06-08 2011-11-23 广州视睿电子科技有限公司 一种usb设备识别计算机操作系统的方法及装置
CN102955755B (zh) * 2011-08-23 2016-03-02 华为终端有限公司 数据卡与主机间通信异常的修复方法及数据卡
CN102375786B (zh) * 2011-10-18 2014-09-10 中兴通讯股份有限公司 Usb设备自动识别操作系统的方法及系统
CN102521186B (zh) * 2011-11-22 2015-01-14 飞天诚信科技股份有限公司 一种USB Key及其与终端进行通信的方法
CN102890662B (zh) * 2012-10-19 2016-10-05 无锡海森诺科技有限公司 通过对usb hid设备进行二次枚举以识别主机操作系统的方法
CN103092799B (zh) * 2012-12-28 2015-07-22 飞天诚信科技股份有限公司 一种usb设备及其识别主机操作系统的方法
CN104156328B (zh) * 2013-05-15 2019-02-05 中兴通讯股份有限公司 一种识别操作系统类型的方法及usb设备
US9170828B2 (en) * 2013-05-16 2015-10-27 Microsoft Technology Licensing, Llc. Extraction of operating system-specific characteristics via a communication interface
CN104182374B (zh) 2013-05-28 2018-09-28 南京中兴软件有限责任公司 Usb设备及其自动识别微软窗口化操作系统版本的方法
CN104516842A (zh) * 2013-09-29 2015-04-15 中兴通讯股份有限公司 一种usb设备快速适配操作系统的方法及usb设备
WO2015096129A1 (en) * 2013-12-27 2015-07-02 Intel Corporation Apparatus, system and article for smart card device and associated host device
US10275798B1 (en) 2014-04-30 2019-04-30 Facebook, Inc. Tracking analytic information for deep links between mobile applications executing on a client device
CN105279110B (zh) * 2014-07-25 2018-07-27 南京中兴软件有限责任公司 一种usb设备识别主机系统的方法及usb设备
CN104281825B (zh) * 2014-09-29 2017-06-06 飞天诚信科技股份有限公司 一种基于智能sd卡的读卡器的工作方法
TW201702805A (zh) * 2015-07-06 2017-01-16 Dexin Corp 辨識電腦系統之輸入裝置及其辨識方法
CN106126446B (zh) * 2016-06-22 2019-01-04 飞天诚信科技股份有限公司 一种USB设备及其识别MacOS系统的方法
CN106372009B (zh) * 2016-08-30 2018-11-30 飞天诚信科技股份有限公司 一种Mac系统中与USB设备通讯的方法及装置
CN106383796B (zh) * 2016-10-18 2019-06-14 广州视睿电子科技有限公司 一种主机操作系统类型的识别方法及系统
CN108733519B (zh) * 2017-04-14 2022-08-16 中兴通讯股份有限公司 一种usb设备的配置方法及主机
CN109173239A (zh) * 2018-08-29 2019-01-11 深圳市七熊科技有限公司 游戏主机识别方法、装置、计算机设备及存储介质
JP7386012B2 (ja) * 2019-07-30 2023-11-24 株式会社ワコム 情報入力装置、方法、及びプログラム
CN112068893B (zh) * 2020-11-12 2021-03-16 飞天诚信科技股份有限公司 一种usb设备及其区分移动设备操作系统的方法

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1464387A (zh) * 2002-06-26 2003-12-31 联想(北京)有限公司 硬件设备驱动程序的安装方法及计算机
CN101078985A (zh) * 2006-05-23 2007-11-28 国际商业机器公司 用于识别在计算机系统上运行的操作系统的方法和设备
CN101957807A (zh) * 2010-09-16 2011-01-26 北京飞天诚信科技有限公司 USB设备识别主机Windows操作系统版本类型的方法

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6389495B1 (en) * 1999-01-16 2002-05-14 Cypress Semiconductor Corp. Dedicated circuit and method for enumerating and operating a peripheral device on a universal serial bus
US6816897B2 (en) * 2001-04-30 2004-11-09 Opsware, Inc. Console mapping tool for automated deployment and management of network devices
US7904960B2 (en) 2004-04-27 2011-03-08 Cisco Technology, Inc. Source/destination operating system type-based IDS virtualization
TW200943188A (en) * 2008-04-01 2009-10-16 Sunplus Innovation Technology Inc A method for automatically detecting an operating system on a USB device
US8661164B2 (en) * 2010-08-24 2014-02-25 Mediatek Inc. Method of USB device enumeration including detecting the operating system type of the USB host
CN101916238B (zh) * 2010-08-26 2012-01-25 华为终端有限公司 数据卡识别操作系统的方法、装置及通信系统

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1464387A (zh) * 2002-06-26 2003-12-31 联想(北京)有限公司 硬件设备驱动程序的安装方法及计算机
CN101078985A (zh) * 2006-05-23 2007-11-28 国际商业机器公司 用于识别在计算机系统上运行的操作系统的方法和设备
CN101957807A (zh) * 2010-09-16 2011-01-26 北京飞天诚信科技有限公司 USB设备识别主机Windows操作系统版本类型的方法

Also Published As

Publication number Publication date
US8862790B2 (en) 2014-10-14
CN101957807B (zh) 2012-08-08
US20130031277A1 (en) 2013-01-31
CN101957807A (zh) 2011-01-26

Similar Documents

Publication Publication Date Title
WO2012034524A1 (zh) Usb设备识别主机windows操作系统版本类型的方法
US8725909B2 (en) Method for identifying host operating system by universal serial bus (USB) device
TWI393009B (zh) 資料共享及傳輸之系統及方法
JP5065297B2 (ja) Mmc/sdデバイスからホストデバイスをブートする方法,mmc/sdデバイスからブート可能なホストデバイス及びホストデバイスをブートできるmmc/sdデバイス
US9411990B2 (en) Working method of a multi-slot card reader based on the standard CCID protocol
WO2014101626A1 (zh) 一种usb设备及其识别主机操作系统的方法
US20080276012A1 (en) Driver Loading via a PnP Device
US10304546B2 (en) External storage device and method of setting reference frequency for the same
US20110099311A1 (en) Communication system, communication apparatus, control method therefor, and computer program
JP2002300229A (ja) Usb通信制御装置、usb通信システムおよびusb通信制御方法
US8850086B2 (en) SD switch box in a cellular handset
TW201229908A (en) Method and apparatus for integrating driver(s) of a portable device into the portable device
US8527667B2 (en) Apparatuses and methods for transferring data
TWI416418B (zh) 資料傳輸控制器、裝置及其方法
WO2020206879A1 (zh) Pcie宽度自动适配方法、装置及电子设备和存储介质
US20160077986A1 (en) Electronic apparatus providing real-time switching and sharing of usb electronic devices among hosts
WO2013049980A1 (zh) 一种转接装置及转接方法
US8996771B1 (en) System and method for communication via universal serial bus
JP3714420B2 (ja) データ転送制御装置、電子機器、プログラム及び電子機器の製造方法
TWM591654U (zh) 讀卡機及資料讀寫系統
JP7372385B1 (ja) 情報処理装置および制御方法
TWI525440B (zh) A data latching device for starting an electronic device and a method of starting the electronic device
TWI718601B (zh) 讀卡機、資料讀寫系統及其讀寫方法
JP2023040804A (ja) ポートコントローラ、電子機器
TWI416338B (zh) 資料通訊系統中進行通訊的計算裝置、資料通訊系統中通訊的方法以及資料通訊系統

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11824594

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 13640997

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11824594

Country of ref document: EP

Kind code of ref document: A1