Patent Publication Number: US-8527670-B2

Title: Method and apparatus for modifying USB device driver matching information

Description:
CROSS-REFERENCE TO RELATED APPLICATION 
     This application is a continuation of International Application No. PCT/CN2010/079326, filed on Dec. 1, 2010, which claims priority to Chinese Patent Application No. 200910249779.X, filed on Dec. 2, 2009, both of which are hereby incorporated by reference in their entireties. 
    
    
     FIELD OF THE INVENTION 
     The present invention relates to the USB device field, and in particular, to a method and an apparatus for modifying a USB device driver matching information. 
     BACKGROUND OF THE INVENTION 
     According to a USB (Universal Serial Bus, universal serial bus) specification, a device driver matching string of a USB device mainly has the following three formats: The first format is formed by a vid (vendor identification, vendor identification), a PID (product identification, product identification), and an MI (Multiple-Interface, Product-Port) number, which is represented in the following form: vid_xxxx&amp;pid_yyyy&amp;mi_zz; the second format is formed by a vid, a subclass (device subclass), and a protocol (device protocol type), which is represented in the following form: vid_xxxx&amp;subclass_yy&amp;prot_zz; the third format is formed by a class (device class), a subclass, and a protocol, which is represented in the following form: class_xx&amp;subclass_yy&amp;prot_zz. 
     For the first format and the second format, vids may be used to identify different vendors. However, a Windows system does not support the second format and the third format cannot identify each vendor. Therefore, most device driver matching strings of USB devices that are manufactured by each OEM (original equipment manufacturer, original equipment manufacturer) use the device driver matching strings of the first format. In addition, each vendor generally has a suite of drivers applicable to all products of a same kind, and products of the same kind are differentiated by using different PIDs. 
     To enable a device driver to correctly match a device, a device driver matching string list corresponding to this kind of device needs to be preset in an operating system. When a device requires a driver, it is necessary only to obtain a device driver matching string of the device and search the device driver matching string list for a device driver corresponding to the device driver matching string. 
     In the process of implementing the matching of the device driver, the inventor finds that the prior art has at least following problems: A defect of the device driver matching string of the first format is that the device driver matching string is limited to the PID of the device; once the PID is changed, a driver matching file needs to be modified, which increases costs in maintenance and certification. 
     SUMMARY OF THE INVENTION 
     Embodiments of the present invention provide a method and an apparatus for modifying a USB device driver matching information, so that after a RD or a port number of a device is changed, a driver corresponding to the device can still be determined without modifying a driver matching file, which saves costs in the driver maintenance and certification. 
     To achieve the foregoing objectives, embodiments of the invention provide the following technical solutions: 
     A method for modifying a USB device driver matching information includes: 
     capturing, by a filter driver, a request for querying device information when a plug-and-play manager sends the request for querying device information to a physical device object, and sending the captured request for querying device information to an enumeration driver: 
     receiving, by the filter driver, device information that is returned, according to the request for querying device information, by the enumeration driver, and forming, according to the returned device information and compatibility information of the device, a device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type; and 
     sending the formed device driver matching string to the plug-and-play manager. 
     An apparatus for modifying a USB device driver matching information includes: 
     an information request capturing module, configured to capture a request for querying device information when a plug-and-play manager sends the request for querying device information to a physical device object; 
     an information request sending module, configured to send the request for querying device information captured by the information request capturing module to an enumeration driver; 
     an information receiving module, configured to receive device information that is returned, according to the request for querying device information, by the enumeration driver; 
     a forming module, configured to form, according to the returned device information and compatibility information of the device, a device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type; and 
     a string sending module, configured to send the device driver matching string formed by the forming module to the plug-and-play manager. 
     In some embodiments of the present disclosure, the filter driver is added on the enumeration driver; when the plug-and-play manager sends the request for querying device information to the physical device object, the filter driver captures the request for querying device information; in addition, after the enumeration driver returns the device information according to the request for querying device information, the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type is formed according to the returned device information and the compatibility information of the device, and the formed device matching string is sent to the plug-and-play manager. In this way, an operating system may implement matching of a device driver program according to information about the vendor identification, the device subclass, and the device protocol type in the device driver matching string. In some embodiments, for a device vendor, only a device driver matching string of the device driver program needs to be compiled according to the device subclass and the device protocol type to implement matching of a driver program for devices of a same kind; subsequently, no matter how product identifications or product-port numbers of the devices of the same kind are changed, the device driver matching string of the devices of the same kind does not need to be recompiled. In this way, a device driver matching string of products of a same kind or ports of a same kind is developed only once and is reused, which may greatly save the costs in driver maintenance and certification during massive production. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
       To make the technical solutions according to the embodiments of the present invention or in the prior art clearer, the accompanying drawings for illustrating the embodiments or the prior art are briefly described below. Apparently, the accompanying drawings in the following description are only some embodiments of the present invention, and persons of ordinary skill in the art may derive other accompanying drawings from these accompanying drawings without creative efforts. 
         FIG. 1  is a flowchart of a method for modifying a USB device driver matching string according to a first embodiment of the present invention; 
         FIG. 2  is a flowchart of a method for modifying a USB device driver matching string according to a second embodiment of the present invention; 
         FIG. 3  is a block diagram of an apparatus for modifying a USB device driver matching string according to a third embodiment of the present invention; and 
         FIG. 4  is a block diagram of an apparatus for modifying a USB device driver matching string according to a fourth embodiment of the present invention. 
     
    
    
     DETAILED DESCRIPTION OF THE EMBODIMENTS 
     The technical solutions of the present invention are described clearly and completely hereunder with reference to the accompanying drawings. Apparently, the embodiments described below are exemplary only, without covering all embodiments of the present invention. Persons of ordinary skill in the art may derive other embodiments from the embodiments given herein without making any creative effort, and all such embodiments are covered in the protection scope of the present invention. 
     Embodiment 1 
     The first embodiment of the present invention provides a method for modifying a USB device driver matching string. As shown in  FIG. 1 , the method includes: 
     Step  101 : When a plug-and-play manager sends a request for querying device information to a physical device object, a filter driver captures the request for querying device information, and sends the captured request for querying device information to an enumeration driver, where the filter driver is a driver program newly added on the enumeration driver. 
     The captured request for querying device information is sent to the enumeration driver, so that the enumeration driver returns device information according to the query request, where the device information returned by the enumeration driver is in the form of a string, the device information may include a device vendor identification, a product identification, and a product-port number, and the device information may be represented in the following form: vid_xxxx&amp;pid_yyyy&amp;mi_zz. 
     Step  102 : The filter driver receives the device information that is returned, according to the request for querying device information, by the enumeration driver, and forms, according to the returned device information and compatibility information of the device, a device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type, where the device driver matching string may be represented in the following form: vid_xxxx&amp;subclass_yy&amp;prot_zz. 
     The compatibility information of the device is in the form of a string; the compatibility information may include a device class, a device subclass, and a device protocol type; and the compatibility information may be represented in the following form: class_xx&amp;subclass_yy&amp;prot_zz. Before the filter driver forms, according to the returned device information and the compatibility information of the device, the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type, the filter driver may obtain the compatibility information of the device by sending a request for querying compatibility information of the device to the physical device object. 
     Step  103 : Send the formed device driver matching string to the plug-and-play manager, so that the plug-and-play manager found, according to the formed device driver matching string, a driver program that matches the physical device. 
     In this embodiment of the present invention, the filter driver is added on the enumeration driver; when the plug-and-play manager sends the request for querying device information to the physical device object, the filter driver captures the request for querying device information; in addition, after the enumeration driver returns the device information according to the request for querying device information, the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type is formed according to the returned device information and the compatibility information of the device, and the formed device driver matching string is sent to the plug-and-play manager. In this way, an operating system may implement matching of a device driver program according to information about the vendor identification, the device subclass, and the device protocol type in the device driver matching string. In some embodiments, for a device vendor, only a device driver matching string of the device driver program needs to be compiled according to the device subclass and the device protocol type to implement matching of a driver program for devices of a same kind; subsequently, no matter how product identification or product-port numbers of the devices of the same kind are changed, the device driver matching string of the devices of the same kind does not need to be recompiled. In this way, a device driver matching string of products of a same kind or ports of a same kind is developed only once and is reused, which may greatly save costs in driver maintenance and certification during massive production. 
     Embodiment 2 
     The second embodiment of the present invention provides a method for modifying a USB device driver matching string. As shown in  FIG. 2 , the method includes: 
     Step  201 : When a plug-and-play manager sends a request for querying a device list, a filter driver captures the request for querying a device list, and sends the captured request for querying a device list to an enumeration driver, where the filter driver is a driver program newly added on the enumeration driver. 
     The captured request for querying a device list is sent to the enumeration driver, so that the enumeration driver enumerates all devices according to the request for querying a device list, and returns a device list of all the enumerated devices to the plug-and-play manager. Further, to enable the filter driver to know that the operation that the enumeration driver enumerates all the devices according to the request for querying a device list has been finished, a completion callback function may be registered for the request for querying a device list after the request for querying a device list is captured. 
     Step  202 : When the enumeration driver returns a device list according to the request for querying a device list, the filter driver receives the device list that is returned, according to the request for querying a device list, by the enumeration driver, creates a filter device object for each device in the device list according to the device list, and adds the created filter device object to a corresponding child device stack. 
     Further, when the enumeration driver returns the device list according to the request for querying a device list, a system may automatically invoke the completion callback function registered for the request for querying a device list so as to perform the following operations: The filter driver creates a filter device object for each device in the device list according to the device list that is returned by the enumeration driver, and adds the created Filter device object to the corresponding child device stack. In this way, it may be ensured that the newly added filter driver can capture, according to the filter device object in the child device stack, a request for querying device information sent by the plug-and-play manager, and can modify device information returned by the enumeration driver. 
     Step  203 : Send the device list returned by the enumeration driver to the plug-and-play manager, so that the plug-and-play manager sends the request for querying device information to a physical device object in the device list according to the device list. 
     Step  204 : When the plug-and-play manager sends the request for querying device information to the physical device object, the filter driver captures the request for querying device information, and sends the captured request for querying device information to the enumeration driver. 
     The captured request for querying device information is sent to the enumeration driver, so that the enumeration driver returns the device information according to the query request, where the device information returned by the enumeration driver is in a form of a string, the device information may include a device vendor identification, a product identification, and a product-port number, and the device information may be represented in the following form: vid_xxxx&amp;pid_yyyy&amp;mi_zz. Further, to enable the filter driver to know that the operation that the enumeration driver enumerates the device information according to the request for querying device information has been finished, a completion callback function may be registered for the request for querying device information after the request for querying device information is captured. 
     Step  205 : When the enumeration driver returns the device information according to the request for querying device information, the filter driver receives the device information returned by the enumeration driver, and forms, according to the returned device information and compatibility information of the device, a device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type, where the device driver matching string may be represented in the following form: vid_xxxx&amp;subclass_yy&amp;prot_zz. 
     Further, when the enumeration driver returns the device information according to the request for querying device information, the system may automatically invoke the completion callback function registered for the request for querying device information so as to perform the following operation: A device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type is formed according to the returned device information and the compatibility information of the device. 
     The compatibility information of the device is in the form of a string; the compatibility information may include a device class, a device subclass, and a device protocol type; and the compatibility information may be represented in the following form: class_xx&amp;subclass_yy&amp;prot_zz. Before the filter driver forms, according to the returned device information and the compatibility information of the device, the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type, the filter driver may obtain the compatibility information of the device by sending a request for querying compatibility information of the device to the physical device object. 
     Step  206 : Send the formed device driver matching string to the plug-and-play manager, so that the plug-and-play manager found, according to the formed device driver matching string, a driver program that matches the physical device. 
     In this embodiment of the present invention, the filter driver is added on the enumeration driver; the added filter driver creates a corresponding filter device object for each device enumerated by the enumeration driver, and adds the created device object to the corresponding child device stack so as to establish a relationship between the filter driver and the device object; when the plug-and-play manager sends the request for querying device information to the physical device object, the added filter driver captures the request for querying device information; in addition, after the enumeration driver returns the device information according to the request for querying device information, the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type is formed according to the returned device information and the compatibility information of the device, and the formed device driver matching string is sent to the plug-and-play manager. In this way, an operating system may implement matching or a device driver program according to information about the vendor identification, the device subclass, and the device protocol type in the device driver matching string. In this embodiment of the present invention, for a device vendor, only a device driver matching string of the device driver program needs to be compiled according to the device subclass and the device protocol type to implement matching of a driver program for devices of a same kind; subsequently, no matter how product identifications or product-port numbers of the devices of the same kind are changed, the device driver matching string of the devices of the same kind does not need to be recompiled. In this way, a device driver matching string of products of a same kind or ports of a same kind is developed only once and is reused, which may greatly save costs in driver maintenance and certification during massive production. 
     Embodiment 3 
     This embodiment of the present invention provides an apparatus for modifying a USB device driver matching string. As shown in  FIG. 3 , the apparatus includes an information request capturing module  31 , an information request sending module  32 , an information receiving module  33 , a forming module  34 , and a string sending module  35 . 
     The information request capturing module  31  is configured to capture a request for querying device information when a plug-and-play manager sends the request for querying device information to a physical device object. 
     After the request for querying device information is captured, the information request sending module  32  is configured to send the request for querying device information captured by the information request capturing module  31  to an enumeration driver, so that the enumeration driver returns device information according to the query request. The device information returned by the enumeration driver is in a form of a string; the device information includes a device vendor identification, a product identification, and a product-port number; and the device information may be represented in the following form: vid_xxxx&amp;pid_yyyy&amp;mi_zz. 
     When the enumeration driver returns the device information after receiving the request for querying device information, the information receiving module  33  is configured to receive the device information returned by the enumeration driver. 
     The forming module  34  is configured to form, according to the returned device information and compatibility information of the device, a device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type, where the device driver matching string may be represented in the following form: vid_xxxx&amp;subclass_yy&amp;prot_zz. 
     The string sending module  35  is configured to send the device driver matching string formed by the forming module  34  to the plug-and-play manager, so that the plug-and-play manager found, according to the formed device driver matching string, a driver program matching the physical device. 
     The compatibility information of the device is in the form of a string; the compatibility information may include a device class, a device subclass, and a device protocol type; and the compatibility information may be represented in the following form: class_xx&amp;subclass_yy&amp;prot_zz. Before the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type is formed according to the returned device information and the compatibility information of the device, a request for querying compatibility information of the device is sent to the physical device object to obtain the compatibility information of the device. 
     In this embodiment of the present invention, when the plug-and-play manager sends the request for querying device information to the physical device object, the request for querying device information is captured: in addition, after the enumeration driver returns the device information according to the request for querying device information, the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type is formed according to the returned device information and the compatibility information of the device, and the formed device driver matching string is sent to the plug-and-play manager. In this way, an operating system may implement matching of a device driver program according to information about the vendor identification, the device subclass, and the device protocol type in the device driver matching string. In this embodiment of the present invention, for a device vendor, only a device driver matching string of the device driver program needs to be compiled according to the device subclass and the device protocol type to implement matching of a driver program for devices of a same kind; subsequently, no matter how product identifications or product-port numbers of the devices of the same kind are changed, the device driver matching string of the devices of the same kind does not need to be recompiled. In this way, a device driver matching string of products of a same kind or ports of a same kind is developed only once and is reused, which may greatly save costs in driver maintenance and certification during massive production. 
     Embodiment 4 
     This embodiment of the present invention provides an apparatus for modifying a USB device driver matching string. As shown in  FIG. 4 , the apparatus includes a list request capturing module  41 , a list request sending module  42 , a list receiving module  43 , a creating module  44 , an adding module  45 , an information request capturing module  46 , an information request sending module  47 , an information receiving module  48 , a forming module  49 , and a string sending module  410 . 
     The list request capturing module  41  is configured to capture a request for querying a device list when a plug-and-play manager sends the request for querying a device list. 
     The list request sending module  42  is configured to send the request for querying a device list captured by the list request capturing module  41  to an enumeration driver, so that the enumeration driver enumerates all devices according to the request for querying a device list and returns a list of all the enumerated devices to the plug-and-play manager. To enable the filter driver to know that the operation that the enumeration driver enumerates all the devices according to the request for querying a device list has been finished, a completion callback function is generally registered for the request for querying a device list after the request for querying a device list is captured. 
     When the enumeration driver returns a device list according to the request for querying a device list, the list receiving module  43  is configured to receive the device list that is returned, according to the request for querying a device list, by the enumeration driver. 
     The creating module  44  is configured to create a filter device object for each device in the device list according to the device list received by the list receiving module  43 . 
     The adding module  45  is configured to: add the filter device object created by the creating module  44  to a corresponding child device stack; and after adding the filter device object to the corresponding child device stack, send the device list returned by the enumeration driver to the plug-and-play manager, so that the plug-and-play manager sends a request for querying device information to a physical device object in the list according to the device list. When the enumeration driver returns the device list according to the request for querying a device list, a system may automatically invoke the completion callback function registered for the request for querying a device list so as to create a filter device object for each device in the device list according to the returned device list, and add the created filter device object to the corresponding child device stack. In this way, it may be ensured that the request for querying device information sent by the plug-and-play manager can be captured according to the filter device object in the child device stack, and device information returned by the enumeration driver can be modified. 
     The information request capturing module  46  is configured to capture the request for querying device information when the plug-and-play manager sends the request for querying device information to a physical device object. 
     After the information request is captured, the information request sending module  47  is configured to send the request for querying device information captured by the information request capturing module  46  to the enumeration driver, so that the enumeration driver returns the device information according to the query request, where the device information returned by the enumeration driver is in a form of a string, the device information includes a device vendor identification, a product identification, and a product-port number, and the device information may be represented in the following form: vid_xxxx&amp;pid_yyyy&amp;mi_zz. 
     When the enumeration driver returns according to the request for querying device information, the information receiving module  48  is configured to receive the device information returned by the enumeration driver. 
     After the device information is received, the forming module  49  is configured to form, according to the returned device information and compatibility information of the device, a device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type, where the device driver matching string may be represented in the following form: vid_xxxx&amp;subclass_yy&amp;prot_zz. 
     The string sending module  410  is configured to send the device driver matching string formed by the forming module  49  to the plug-and-play manager, so that the plug-and-play manager found, according to the formed device driver matching string, a driver program matching the physical device. The compatibility information of the device is in the form of a string; the compatibility information includes a device class, a device subclass, and a device protocol type; and the compatibility information may be represented in the following form: class_xx&amp;subclass_yy&amp;prot_zz. 
     Before a new device driver matching string is formed by the device information returned by the enumeration driver and the compatibility information of the device, the apparatus for modifying a USB device driver matching string may further include a compatibility information obtaining module  411 . The compatibility information obtaining module  411  is configured to send a request for querying compatibility information of the device to the physical device object to obtain the compatibility information of the device. 
     Further, to enable the filter driver to know that the operation that the enumeration driver enumerates the device information according to the request for querying device information has been finished, the apparatus for modifying a USB device driver matching string may further include a registering module  412 . The registering module  412  is configured to register a completion callback function for the request for querying device information before the information request capturing module  46  sends the captured request for querying device information to the enumeration driver, so that when the enumeration driver returns the device information according to the request for querying device information, the system automatically invokes the registered completion callback function to form, according to the returned device information and the compatibility information of the device, a device driver matching string that includes a device vendor identification, a device subclass, and a device protocol type. 
     In this embodiment of the present invention, the filter driver creates a corresponding filter device object for each device enumerated by an enumeration driver, and adds the created device object to the corresponding child device stack so as to establish a relationship between the filter driver and the device object; when the plug-and-play manager sends the request for querying device information to a physical device object, the filter driver captures the request for querying device information; in addition, after the enumeration driver returns the device information according to the request for querying device information, the device driver matching string that includes the device vendor identification, the device subclass, and the device protocol type is formed according to the returned device information and the compatibility information of the device, and the formed device driver matching string is sent to the plug-and-play manager. In this way, an operating system may implement matching of a device driver program according to information about the vendor identification, the device subclass, and the device protocol type in the device driver matching string. In this embodiment of the present invention, for a device vendor, only a device driver matching string of the device driver program needs to be compiled according to the subclass and protocol to implement matching of a driver program for devices of a same kind; subsequently, no matter how product identifications or product-port numbers of the devices of the same kind is changed, the device driver matching string of the devices of the same kind does not need to be recompiled. In this way, a device driver matching string of products of a same kind or ports of a same kind is developed only once and is reused, which may greatly save costs in driver maintenance and certification during massive production. 
     Embodiments of the present invention describe only a special case that a filter driver is used to modify a device driver matching string. However, through this technical solution, all information that the enumeration driver returns to the plug-and-play manager may be modified, which also falls within the protection scope of the present invention. 
     Based on the preceding description about implementation manners, it may be understandable to those skilled in the art that the present invention may be implemented by software in addition to a necessary universal hardware platform or by hardware only. In most circumstances, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention or the portions contributing to the prior art may be embodied by a software product. The software product is stored in a readable storage medium, for example, a floppy disk, a hard disk, or a Compact Disc-Read Only Memory (CD-ROM) of a computer, and incorporate several instructions to instruct a computer device (for example, a personal computer, a server, or a network device) to execute the method in each of the embodiments of the present invention. 
     The preceding descriptions are merely exemplary embodiments of the present invention, but not intended to limit the protection scope of the present invention. Any modification or replacement readily conceivable by those skilled in the art in the scope of the technology disclosed herein shall fall within the protection scope of the present invention. Therefore, the scope of the present invention is subject to the appended claims.