Communication request processing method and apparatus, USB device, and storage medium
Patent Information
- Application Number
- CN202310009608.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-04
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2043-01-04
AI Technical Summary
[0003]相关技术中,USB设备在接收到USB主机发送的请求后,会针对请求历遍查找对应的处理函数,以基于查找到的处理函数响应请求进行数据处理,但是,由于USB主机的请求是多样且随机性的,且处理函数的数量较多,需要耗费大量的计算资源查找处理函数,降低处理函数的查找性能
[0053]本申请中提供通信请求的处理方法、装置、USB设备和存储介质,USB设备通过接收主机发送的标准请求,并根据所述标准请求中的字段信息,提取所述标准请求中的目标信息;并根据所述目标信息确定目标地址;然后调用所述目标地址对应的目标处理函数,通过所述目标处理函数响应所述标准请求进行数据处理。本方案通过提取请求中的目标信息,并根据目标信息确定目标处理函数对应的目标地址,然后根据目标地址直接调用对应的目标处理函数,摒弃根据所述标准请求与处理函数进行历遍查找对应匹配的技术方案,降低处理函数的查找计算量,提升处理函数的查找效率,同时减轻了处理函数查找的程序重量,节省内存,进而提升处理函数的查找性能。
Smart Images

Figure CN115952125B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data communication technology, and specifically to a method, apparatus, USB device, and storage medium for processing communication requests. Background Technology
[0002] A USB device is a piece of hardware at the end of a USB cable that typically communicates with a USB host to perform tasks assigned by the host. Before assigning tasks to a USB device, the host configures it, usually through device requests.
[0003] In related technologies, after receiving a request from a USB host, a USB device will search for the corresponding processing function for the request and then process the data based on the found processing function. However, since the requests from the USB host are diverse and random, and there are many processing functions, a lot of computing resources are needed to find the processing function, which reduces the performance of the processing function search. Summary of the Invention
[0004] This application provides a method, apparatus, USB device, and storage medium for processing communication requests, aiming to solve the technical problem that when a USB device responds to a request from a USB host, it needs to consume a lot of computing resources to find the processing function, which reduces the search performance of the processing function, reduces the amount of data processing required to find the processing function, and improves the search performance of the processing function.
[0005] In a first aspect, this application provides a method for processing communication requests, applied to a USB device, the method comprising:
[0006] Receive a standard request sent by the host, and extract the target information from the standard request based on the field information in the standard request;
[0007] Determine the target address based on the target information;
[0008] The target processing function corresponding to the target address is invoked, and the target processing function responds to the standard request to perform data processing.
[0009] In one possible implementation of this application, the target information includes type information, object information, and request parameter information, wherein the type information, object information, and request parameter information are used to calculate the target address.
[0010] In one possible implementation of this application, the step of extracting the target information from the standard request based on the field information in the standard request includes:
[0011] Identify the request type field, request object field, and request parameter information field in the standard request;
[0012] Extract the type information corresponding to the request type field, extract the object information corresponding to the request object field, and extract the request parameter information from the request parameter information field.
[0013] In one possible implementation of this application, the step of extracting the object information corresponding to the request object field includes:
[0014] Identify the bit value corresponding to the field of the requested object;
[0015] Extract the lower four bits of the bit value to obtain the object information corresponding to the requested object field.
[0016] In one possible implementation of this application, determining the target address based on the target information includes:
[0017] The binary request parameter information in the target information is converted into the target base request parameter information to obtain the target information after conversion.
[0018] The target information after conversion to a different base is hashed to obtain the target address corresponding to the target information.
[0019] In one possible implementation of this application, the target information after conversion to a different base is hashed to obtain the target address corresponding to the target information, including:
[0020] If the request parameter information is greater than zero, the request parameter information is corrected according to the preset data correction parameters to obtain the corrected target request parameter information;
[0021] The sum of the type information, object information, and target request parameter information after conversion is calculated to obtain the target address corresponding to the target information.
[0022] In one possible implementation of this application, the step of calling the target processing function corresponding to the target address includes:
[0023] Search a preset target item table, which stores addresses and functions with corresponding relationships;
[0024] Determine whether the target memory unit corresponding to the target address in the target item table is empty;
[0025] Based on the judgment result, perform the operation corresponding to the judgment result.
[0026] In one possible implementation of this application, the step of performing the operation corresponding to the judgment result based on the judgment result includes:
[0027] If the target memory unit corresponding to the target address in the target item table is not empty, then the target processing function within the target memory unit is called; or
[0028] If the target memory unit corresponding to the target address in the target item table is empty, then obtain the processing function corresponding to the USB device;
[0029] The address corresponding to each processing function is determined based on the function field information in each processing function;
[0030] Identify the processing function corresponding to the address that is the same as the target address as the target processing function, and call the target processing function;
[0031] The target item table is updated based on the correspondence between each address and the processing function.
[0032] In one possible implementation of this application, determining the address corresponding to each processing function based on the function field information in each processing function includes:
[0033] Extract the function field information corresponding to the independent variables in each of the processing functions, and determine the function target information corresponding to the function field information based on the correspondence between the function field information and the field information in the standard request corresponding to the processing function;
[0034] The target information corresponding to each processing function is hashed to obtain the target address corresponding to each processing function.
[0035] In one possible implementation of this application, after calling the target processing function corresponding to the target address, the method further includes:
[0036] When it is detected that the number of first functions of the processing function corresponding to the USB device is different from the number of second functions of the processing function in the target item table, the function field information of each processing function corresponding to the USB device is obtained.
[0037] The address corresponding to each processing function is determined based on the function field information in each processing function;
[0038] The target item table is updated according to the correspondence between each address and each processing function.
[0039] In one possible implementation of this application, before receiving the standard request sent by the host and extracting the target information from the standard request based on the field information in the standard request, the method further includes:
[0040] Obtain all processing functions corresponding to the USB device and create a target item table including at least two memory units;
[0041] Based on the function field information in each of the processing functions, determine the function target information corresponding to each processing function;
[0042] Based on the function target information corresponding to each of the processing functions, determine the target address corresponding to each of the processing functions;
[0043] The target address and the corresponding target processing function are stored in the target item table.
[0044] Secondly, this application provides a communication request processing apparatus, the communication request processing apparatus comprising:
[0045] Receiving and Extraction Module: Used to receive standard requests sent by the host, and extract target information from the standard requests based on the field information in the standard requests;
[0046] Determining module: used to determine the target address based on the target information;
[0047] Calling module: Used to call the target processing function corresponding to the target address, and to process data in response to the standard request through the target processing function.
[0048] Thirdly, this application provides a USB device, the USB device comprising:
[0049] One or more processors;
[0050] Memory; and
[0051] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement a processing method for any of the communication requests described herein.
[0052] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, the computer program being loaded by a processor to perform the steps in any of the communication request processing methods described above.
[0053] This application provides a method, apparatus, USB device, and storage medium for processing communication requests. The USB device receives a standard request sent by a host, extracts target information from the standard request based on field information, determines a target address based on the target information, and then calls the target processing function corresponding to the target address to respond to the standard request and perform data processing. This solution extracts target information from the request, determines the target address corresponding to the target processing function based on the target information, and then directly calls the corresponding target processing function based on the target address. This eliminates the need for a traversal search between the standard request and the processing function to find a match, reducing the computational load of the processing function search, improving the search efficiency of the processing function, and simultaneously reducing the program weight of the processing function search, saving memory, and thus improving the search performance of the processing function. Attached Figure Description
[0054] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0055] Figure 1 This is a schematic diagram illustrating a scenario of the communication request processing method provided in an embodiment of this application;
[0056] Figure 2 This is a schematic flowchart of an embodiment of the communication request processing method provided in this application.
[0057] Figure 3 A flowchart illustrating one implementation method for target information extraction in the communication request processing method provided in this application;
[0058] Figure 4 A flowchart illustrating one implementation method for determining the target address in the communication request processing method provided for the embodiments of this application;
[0059] Figure 5 A flowchart illustrating one implementation of the target processing function call in the communication request processing method provided in this application;
[0060] Figure 6 A flowchart illustrating another implementation of the target processing function call in the communication request processing method provided for the implementation scheme of this application;
[0061] Figure 7 A flowchart illustrating another implementation of the communication request processing method provided for the embodiments of this application;
[0062] Figure 8 This is a schematic diagram of an embodiment of the communication request processing device provided in this application.
[0063] Figure 9 This is a schematic diagram of an embodiment of the USB device provided in this application. Detailed Implementation
[0064] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0065] Understandably, USB devices include USB interfaces. As a high-speed serial bus interface, the USB interface is renowned for its extremely high transmission speed, meeting the application requirements of high-speed data transmission. This bus interface also boasts advantages such as simple power supply, easy port expansion, hot-swapping support, flexible connections, and diverse transmission capabilities. The USB protocol stack, as a hardware-independent software protocol, is responsible not only for USB device access detection, address allocation, and request / response, but also for USB device type abstraction and data transmission—it is the foundation upon which all USB devices depend. Within the core of the entire protocol stack, its central idea is the parsing and response to requests from the USB host.
[0066] In current mainstream protocol stacks, a layered approach is used to parse USB host request commands. Specifically, the code uses numerous switch...case... statements for iteration, or if...else if... statements to loop through the possible values corresponding to each keyword in the request, and then finds the corresponding processing function layer by layer. For example, a typical protocol stack needs to iterate through combinations such as RequestType=0, 1, 2, Request=0,1,2,3,4,5,6,7,8,9,10, etc., and then find the corresponding processing function. There may be more than thirty such combinations, and iteratively searching for the processing function is quite time-consuming.
[0067] Therefore, this application proposes a method, apparatus, USB device, and storage medium for processing communication requests. The method is applied to the processing apparatus for communication requests, which is located within a USB device. The USB device includes one or more processors, a memory, and one or more application programs. The one or more application programs are stored in the memory and configured to be executed by the processor to process the communication request. The USB device can be a terminal, such as a USB device, mobile phone, tablet computer, portable hard drive, flash drive, portable optical drive, card reader, digital camera, digital music player, etc.
[0068] like Figure 1 As shown, Figure 1 This is a schematic diagram of a scenario for processing communication requests according to an embodiment of this application. The scenario for processing communication requests in this embodiment includes a USB device 100 (the USB device 100 integrates a communication request processing device), and a computer-readable storage medium in the USB device 100 that runs the communication request processing method to execute the steps of the communication request processing method.
[0069] Understandable, Figure 1 The USB devices in the scenario of the communication request processing method shown, or the devices contained in the USB devices, do not constitute a limitation on the embodiments of the present invention. That is, the number of USB devices or the types of USB devices contained in the scenario of the communication request processing method, or the number of devices or the types of devices contained in each USB device, do not affect the overall implementation of the technical solution in the embodiments of the present invention, and can all be considered as equivalent substitutions or derivatives of the technical solutions claimed in the embodiments of the present invention.
[0070] The USB device receives standard requests from the host and extracts target information from the fields within the request. It then determines the target address based on this information and calls the corresponding target processing function. This function responds to the standard request and processes the data. By extracting the target information and determining the target address, and then directly calling the function, the process avoids the need for a traversal search between the standard request and the processing function. This reduces the computational load of the function lookup, improves lookup efficiency, and reduces the program weight for lookup, saving memory and ultimately enhancing the performance of the lookup process.
[0071] Furthermore, in the scenario of the communication request processing method of this application, the USB device 100 can be equipped with a display device. The USB device 100 can access the background database 300 (the background database can be located in the local storage of the USB device, or it can be located in the cloud), and the background database 300 stores information related to the processing of communication requests.
[0072] Furthermore, the scenario of the communication request processing method in this application also includes a USB host 400 that communicates with the USB device. The USB host is used to send standard requests to the USB device to perform configuration operations on the USB device so that tasks can be distributed to the USB device in the future.
[0073] Based on the scenario of the above-mentioned communication request processing method, an embodiment of the communication request processing method is proposed.
[0074] like Figure 2 The diagram shown is a flowchart of an embodiment of a communication request processing method in this application. The communication request processing method includes steps S201-S203:
[0075] S201. Receive the standard request sent by the host, and extract the target information from the standard request based on the field information in the standard request.
[0076] The host device is the USB host that corresponds to the USB device.
[0077] Standard requests, i.e., requests sent by the USB host for configuring USB devices, can be exemplified as follows: GetStatus (for the USB host to read the status of a USB device, interface, or endpoint); ClearFeature (for the USB host to clear or disable certain features of a USB device, interface, or endpoint); SetFeature (for setting or enabling feature values of a USB device, interface, or endpoint); SetAddress (for assigning a unique device address to a USB device when it is powered on); and GetDescription (for the USB host to read a specified descriptor of the device, and the USB device to return the specified descriptor to the USB host during the data phase), among other types of standard requests.
[0078] Furthermore, the standard request includes fields such as RequestType, Request, value, and Index, as well as values corresponding to the RequestType, Request, value, and Index fields. The value of the RequestType field is used to determine the standard request object (device, interface, or endpoint), and the value of the Request field is used to determine the type of the standard request.
[0079] The fields include RequestType (request object field), Request (request type field), value (request parameter information field), and Index field.
[0080] The target information, namely, one or more of the values corresponding to the RequestType field, the Request field, the value field, and the Index field, can be understood to be binary, decimal, hexadecimal, etc.; however, this application does not impose specific limitations on it.
[0081] Specifically, this application does not specify the implementation method for the USB device to extract the target information from the standard request based on the field information in the standard request after receiving it from the host. For example:
[0082] In one embodiment of this application, after receiving a standard request sent by the host, the USB device extracts the value corresponding to the target field according to the preset target field, that is, obtains the target information. For example, the target field may include the RequestType field, the Request field, and the value field. That is, the target information includes the value corresponding to the RequestType field, the value corresponding to the Request field, and the value field. It can be understood that the target field may also include the RequestType field and the Request field. That is, the target information includes the value corresponding to the RequestType field and the value corresponding to the Request field.
[0083] In another embodiment of this application, after receiving a standard request sent by the host, the USB device extracts the value of the target field that satisfies the position constraint condition according to the preset target field and the position constraint condition of the value corresponding to the target field. The position constraint condition is, for example, limiting the value to the lower four bits, the higher four bits, or the lower five bits, to avoid the value corresponding to a certain target field having too many bits, that is, the data being too long, causing a data calculation burden, and further improving the data calculation efficiency. The specific position constraint condition is not limited in this application.
[0084] S202. Determine the target address based on the target information.
[0085] The target address is the address where the target processing function corresponding to the standard request is stored. For example, the target address can be a memory address, the memory address corresponding to a mapping table entry, etc., and can be specifically limited according to the storage method of the target processing function.
[0086] Specifically, after receiving a standard request from the host and extracting the target information from the fields in the standard request, the USB device determines the target address based on the target information. This application does not specify a particular implementation method for this, for example:
[0087] In one embodiment of this application, the USB device can look up the target address corresponding to the target information according to a preset mapping table of values and addresses.
[0088] In another embodiment of this application, the USB device can calculate the target parameters corresponding to multiple target information according to a preset calculation formula, or perform data concatenation on multiple target information according to a preset data concatenation method to obtain target parameters, and find the corresponding target address according to the target parameter mapping.
[0089] S203. Call the target processing function corresponding to the target address, and process the data by responding to the standard request through the target processing function.
[0090] The target processing function, i.e., the processing function that responds to standard requests and processes data, can be understood as one of several processing functions. Different standard requests have different corresponding processing functions. For example, these include: `get_status_for_dev`, `get_status_for_if`, and `get_status_for_ep` for requests of type `get_status`; and `clear_feature_for_dev`, `clear_feature_for_if`, and `clear_feature_for_ep` for requests of type `clear_feature`. Here, `if` corresponds to the interface object, `dev` to the device object, and `ep` to the endpoint object. It's important to understand that this is only a partial list of processing functions.
[0091] Specifically, after determining the target address based on the target information, the USB device directly calls the target processing function corresponding to the target address. The target processing function responds to standard requests and performs data processing, thereby achieving accurate and fast voltage control of the target processing function and reducing the amount of data processing.
[0092] Furthermore, based on the above implementation plan, see [link to relevant documentation]. Figure 3 , Figure 3 A flowchart illustrating one implementation of the communication request processing method provided in this application for target information extraction, including steps S301-S302:
[0093] S301. Identify the request type field, request object field, and request parameter information field in the standard request.
[0094] Among them, the request object field is the RequestType field; the request type field is the Request field; and the request parameter information field is the value field.
[0095] Specifically, in the embodiments of this application, after receiving a standard request sent by the host, the USB device identifies the RequestType field, Request field, and value field in the standard request.
[0096] S302. Extract the type information corresponding to the request type field, extract the object information corresponding to the request object field, and extract the request parameter information from the request parameter information field.
[0097] Specifically, this involves extracting the type information corresponding to the request type field (i.e., extracting the value of the RequestType field), the object information corresponding to the request object field (i.e., extracting the value of the Request field), and the request parameter information from the request parameter information field (i.e., extracting the value of the value field). In other words, the target information includes: type information, object information, and request parameter information.
[0098] Specifically, in the implementation scheme of this application, the type information corresponding to the request type field is extracted, including:
[0099] (1) Identify the bit values corresponding to the fields of the request object;
[0100] (2) Extract the bit value at the preset position in the bit value to obtain the object information corresponding to the requested object field.
[0101] Understandably, the preset position can be the lower four bits, the lower five bits, etc. The bit values corresponding to the requested object field are generally quite numerous. In order to avoid the data volume being too large, the object information corresponding to the requested object field is extracted by limiting the extraction of the bit values at the preset position corresponding to the requested object field.
[0102] Specifically, in the implementation scheme of this application, after receiving a standard request sent by the host, the USB device identifies the RequestType field, Request field, and value field in the standard request, and then extracts the lower four bits corresponding to the RequestType field, the value corresponding to the Request field, and the value corresponding to the value field to obtain the target information.
[0103] For example, the lower four bits of the RequestType field are extracted. For instance, if the value of the RequestType field is 00110100, the lower four bits of 0100 are extracted as the lower four bits of the RequestType field.
[0104] Furthermore, based on the above implementation plan, see [link to relevant documentation]. Figure 4 , Figure 4 A flowchart illustrating one implementation of the communication request processing method provided in this application, including steps S401-S402, illustrates the target address determination method.
[0105] S401. Convert the binary request parameter information in the target information into the target base request parameter information to obtain the target information after conversion.
[0106] Among them, the target base request parameter information, that is, the request parameter information corresponding to the target base, can be decimal, hexadecimal, etc., that is, the target base request parameter information, that is, decimal request parameter information, hexadecimal request parameter information, etc.
[0107] It is understandable that the values in the standard request are generally binary values, and binary data is large. Therefore, in the implementation scheme of this application, after the USB device extracts the target information, it converts all the target information into decimal values.
[0108] In other embodiments of this application, it can also be determined whether the number of bits of each target information is greater than a preset threshold. If the number of bits of a target information is greater than the preset threshold, the target information with a number greater than the preset threshold is converted into a decimal number. If the number of bits of a target information is not greater than the preset threshold, the target information with a number greater than the preset threshold is not converted into decimal request parameter information.
[0109] By reducing the amount of data, we can improve computational efficiency and enhance data computing performance.
[0110] S402. Perform hash calculation on the target information after conversion to the new base to obtain the target address corresponding to the target information.
[0111] Specifically, after receiving a standard request from the host, the USB device extracts the target information from the standard request based on the field information in the standard request, converts the binary request parameter information in the target information into target base request parameter information, and performs hash calculation on the converted target information according to a preset hash calculation formula to obtain the target address corresponding to the target information.
[0112] Specifically, in the implementation scheme of this application, a hash calculation is performed on the target information after conversion to a different base to obtain the target address corresponding to the target information. The specific steps include:
[0113] (1) If the request parameter information is greater than zero, the request parameter information is corrected according to the preset data correction parameters to obtain the corrected target request parameter information;
[0114] (2) Calculate the sum of the type information, object information and target request parameter information after conversion to obtain the target address corresponding to the target information.
[0115] The data correction parameter can be a correction coefficient, a correction value, etc. Specifically, in the implementation scheme of this application, the data correction parameter is a correction value. When the request parameter information is greater than zero, the preset data correction parameter is subtracted from the request parameter information to obtain the corrected target request parameter information.
[0116] Specifically, in the implementation scheme of this application, the preset hash calculation formula is as follows:
[0117] M=Request*a+RequestType[b:0]+g(value)
[0118] Where M is the target address, Request*a is the type information, RequestType[b:0] is the object information after conversion to decimal, and g(value) is the corrected target request parameter information.
[0119] That is, the USB device calculates the sum of the converted type information, object information, and target request parameter information to obtain the target address corresponding to the target information.
[0120] Furthermore, based on the above implementation plan, see [link to relevant documentation]. Figure 5 , Figure 5 A flowchart illustrating one embodiment of the target processing function call in the communication request processing method provided for the implementation of this application, including steps S501-S502:
[0121] S501. Search the preset target item table.
[0122] The target item table stores addresses and functions with corresponding relationships. The target item table stores processing functions, and each processing function corresponds to a unique storage address (referred to as address).
[0123] S502. If the target memory unit corresponding to the target address in the target item table is not empty, then call the target processing function within the target memory unit.
[0124] Specifically, after obtaining the target address of the target processing function, the USB device searches a preset target entry table corresponding to the function and address, and determines whether the target memory unit corresponding to the target address in the target entry table is empty; and based on the determination result, it executes the operation corresponding to the determination result. For example, in one embodiment of this application, based on the determination result, the operation corresponding to the determination result is executed as follows: if the target memory unit corresponding to the target address in the target entry table is not empty, then the processing function stored in the target memory unit is the target processing function, and the target processing function in the target memory unit is called.
[0125] It is understood that in some other embodiments of this application, based on the judgment result, the operation corresponding to the judgment result is performed. For example, if the USB device finds that the target memory unit corresponding to the target address in the target item table is empty, it will return information such as no response or request error.
[0126] Furthermore, based on the above implementation plan, see [link to relevant documentation]. Figure 6 , Figure 6 A flowchart illustrating another implementation of the target processing function call in the communication request processing method provided for the embodiments of this application, including steps S601-S605:
[0127] S601. Search the preset target item table.
[0128] S602. If the target memory unit corresponding to the target address in the target item table is empty, then obtain the processing function corresponding to the USB device.
[0129] Specifically, if the target memory unit corresponding to the target address in the target item table is empty, it may be because the processing function in the target item table has not been updated in time or the target address has been calculated incorrectly. In this case, all the processing functions corresponding to the USB device should be retrieved again, that is, all the callable and executable processing functions included in the USB device.
[0130] S603. Determine the target address corresponding to each processing function based on the function field information in each processing function.
[0131] Among them, the function field information in the processing function, that is, the field information corresponding to the independent variable in the processing function. For example, if the processing function is: get_status_for_dev, then the function field information corresponding to the independent variable includes: get_status and dev.
[0132] Specifically, after obtaining the processing function corresponding to the USB device, the USB device extracts the function field information corresponding to the independent variables in each processing function, then looks up the preset mapping table to determine the function target information corresponding to the function field information, and determines the corresponding target address based on the function target information. That is, the target address corresponding to each processing function is calculated. The implementation method of determining the corresponding target address based on the function target information is described in the above implementation scheme. It can be understood that the function target information and the target information extracted according to the standard request correspond to each other. They can be the same or they can be values with a mapping relationship. The target address is the target address mentioned above.
[0133] Specifically, in one embodiment of this application, the address corresponding to each processing function is determined based on the function field information in each processing function, including the following steps:
[0134] (1) Extract the function field information corresponding to the independent variables in each processing function, and determine the function target information corresponding to the function field information based on the correspondence between the function field information and the field information in the standard request corresponding to the processing function.
[0135] It is understandable that a standard request corresponds to a processing function. That is, when a USB device receives a standard request from a USB host, it parses the received request to determine the processing function that should respond to it, and then calls that function to process the request. Specifically, the USB device determines the request type, request parameter object, and request parameters by parsing the field information in the standard request, and then determines the processing function to be called. It is also understandable that the function field information corresponding to the independent variables in the processing function also indicates the processing type, processing object, heat exchange request parameters, and other information. Furthermore, it is understood that the function field information corresponds to the standard request information in the processing function. There is a correspondence between the field information. Specifically, this correspondence can be a mapping table that includes the mapping relationship between function field information and corresponding field information, or a relation table that includes multiple relation groups. Each relation group includes function field information, field information corresponding to the function field information, and function target information corresponding to the function field information. In the implementation scheme of this application, the target information and the function target information have the same value. That is, the function field information and the field information with the corresponding relationship correspond to the same function target information. The function target information is also used as the target information corresponding to the field information. That is, the function target information also includes type information, object information, and request parameter information.
[0136] (2) Perform hash calculation on the target information of each processing function to obtain the target address of each processing function.
[0137] Specifically, for the implementation scheme of the USB device performing hash calculation based on the target value of the function, please refer to the above implementation method of performing hash calculation on the target address based on the target information.
[0138] S604. Determine the processing function corresponding to the address that is the same as the target address as the target processing function, and call the target processing function.
[0139] Specifically, after calculating the address corresponding to each processing function, the USB device compares the target address with the address corresponding to each processing function. If an address that is the same as the target address is found, the processing function corresponding to that address is determined to be the target address function.
[0140] Understandably, if an address matching the target address is not found, the USB device will send a message indicating that the request failed to the USB host.
[0141] S605. Update the target item table according to the correspondence between each address and the processing function.
[0142] Furthermore, after recalculating the address corresponding to the processing function (target address), the USB device deletes the stored data in the target item table and restores the target address and processing function in the target item table to update the target item table.
[0143] Furthermore, in some other embodiments of this application, after calculating the addresses corresponding to each processing function, the USB device may first update the target item table according to the correspondence between the addresses and processing functions, and then the USB device may search the updated target item table. If the target memory unit corresponding to the target address in the target item table is not empty, the target processing function in the target memory unit is called. If the target memory unit corresponding to the target address in the target item table is empty, information such as no response or request error is sent to the display end of the host and / or the USB device.
[0144] It is understood that in some other embodiments of this application, the USB device may also use the original function search method to search for the target processing function when it first searches the target item table and does not find the target processing function. If the target processing function is found, the corresponding target address is calculated based on the target processing function, and the target address corresponding to the target processing function is added to the target item table to update the target item table.
[0145] Furthermore, based on the above implementation plan, see [link to relevant documentation]. Figure 7 , Figure 7 A flowchart illustrating another embodiment of the communication request processing method provided for the implementation of this application includes steps S701-S707:
[0146] S701. Obtain the processing function corresponding to the USB device and create a target item table including at least two memory units.
[0147] The number of memory units is greater than or equal to the number of processing functions.
[0148] Here, a memory unit refers to each storage unit in the target item table, such as one of the columns in the target item table.
[0149] Specifically, obtain the processing function corresponding to the USB device and create a target item table with at least two memory units. For example, if the number of processing functions is num, then create a table with l memory units to store the n processing functions (l>=n).
[0150] S702. Determine the function target information corresponding to each processing function based on the function field information in each processing function.
[0151] Specifically, after the USB device obtains the corresponding processing function and creates a target item table containing at least two memory units, it extracts the function field information corresponding to the independent variables in each processing function. For example, if the processing function is `get_status_for_dev`, then the function field information corresponding to the independent variables includes `get_status` and `dev`. Then, a preset mapping table is searched to determine the target information corresponding to the field information. It can be understood that the target information corresponds to the target information extracted according to the standard request; they can be the same or have a mapping relationship. In this implementation scheme, the function target information is the target information extracted according to the standard request.
[0152] S703. Determine the target address corresponding to each processing function based on the function target information corresponding to each processing function.
[0153] Specifically, after determining the function target information corresponding to each processing function based on the function field information in each processing function, the USB device determines the corresponding target address based on the function target information. The implementation method for determining the target address based on the target information is described above. The target address is the target address mentioned above. Determining the corresponding target address based on the target information means calculating the target address corresponding to each processing function.
[0154] S704. Store the target address and the corresponding target processing function in the target item table.
[0155] Furthermore, the USB device determines the target address corresponding to each processing function based on the target information corresponding to each processing function, and stores the target processing function corresponding to the target address in the target entry table. For example, the target address can be stored as the index of the corresponding processing function.
[0156] S705: Receive the standard request sent by the host, and extract the target information from the standard request based on the field information in the standard request.
[0157] S706. Determine the target address based on the target information.
[0158] S707. Call the target processing function corresponding to the target address, and process the data in response to the standard request through the target processing function.
[0159] Specifically, the implementation methods of steps S705-S707 can be found in any of the above implementation schemes.
[0160] By creating a target item table, the amount of data stored is reduced, and data retrieval performance is improved.
[0161] Furthermore, based on the above implementation scheme, this application also provides another implementation scheme for processing communication requests. After the USB device calls the target processing function corresponding to the target address to respond to the standard request and perform data processing through the target processing function, the method further includes the following steps:
[0162] (1) When the number of first functions of the processing function corresponding to the USB device is different from the number of second functions of the processing function in the target item table, the function field information of each processing function corresponding to the USB device is obtained.
[0163] The first function count is the total number of all processing functions that the USB device can call, and the second function count is the total number of all processing functions in the target item table.
[0164] Specifically, after a USB device calls the target processing function corresponding to the target address and processes data in response to a standard request, it can periodically check the number of all processing functions that the USB device can call to obtain a first number of functions. This first number of functions is then compared with a second number of functions. If the first number of functions is greater than the second number, it means that the processing functions in the target item table do not cover all the processing functions that the USB device can call, and the target item table needs to be updated. That is, new processing functions maliciously called by the device need to be added to the target item table. If the first number of functions is less than the second number of functions, it means that there are functions that the USB device cannot call in the target item table, and these functions need to be deleted from the target item table.
[0165] (2) Determine the address of each processing function based on the function field information in each processing function;
[0166] (3) Update the target item table according to the correspondence between each address and each processing function.
[0167] It can be understood that the implementation schemes for steps (2)-(3) are as shown in the above implementation scheme. By updating the target item table, the validity and completeness of the processing functions in the target item table are improved, thereby enhancing the parsing performance of standard requests and the accuracy of responses.
[0168] This application provides a method for processing communication requests. A USB device receives a standard request sent by a host, extracts target information from the standard request based on its field information, determines the target address based on the target information, and then calls the target processing function corresponding to the target address to process data in response to the standard request. This solution extracts the target information from the request, determines the target address corresponding to the target processing function based on the target information, and then directly calls the corresponding target processing function based on the target address. This eliminates the need for a traversal search between the standard request and the processing function to find a match, reducing the computational load of the processing function search, improving the search efficiency of the processing function, and simultaneously reducing the program weight of the processing function search, saving memory, and thus improving the search performance of the processing function.
[0169] To better implement the communication request processing method in the embodiments of this application, based on the communication request processing method, the embodiments of this application also provide a communication request processing apparatus, such as... Figure 8 As shown, the communication request processing device includes modules 801-803:
[0170] Receive and extract module 801: Used to receive standard requests sent by the host and extract target information from the standard requests based on the field information in the standard requests;
[0171] Module 802: Used to determine the target address based on the target information;
[0172] Call module 803: Used to call the target processing function corresponding to the target address, and to process data in response to standard requests through the target processing function.
[0173] In one possible implementation of this application, the target information includes: type information, object information, and request parameter information; the type information, the object information, and the request parameter information are used to calculate the target address.
[0174] In one possible implementation of this application, the receiving extraction module 801 is configured to extract target information from the standard request based on field information in the standard request, specifically including:
[0175] Identify the request type field, request object field, and request parameter information field in the standard request;
[0176] Extract the type information corresponding to the request type field, extract the object information corresponding to the request object field, and extract the request parameter information from the request parameter information field.
[0177] In one possible implementation of this application, the receiving extraction module 801 is used to extract object information corresponding to the requested object field, specifically including:
[0178] Identify the bit values corresponding to the fields in the request object;
[0179] Extract the lower four bits of the bit value to obtain the object information corresponding to the requested object field.
[0180] In one possible implementation of this application, the determining module 802 is used to determine the target address based on the target information, specifically including:
[0181] Convert the binary request parameter information in the target information into the target base request parameter information to obtain the target information after conversion;
[0182] The target information after conversion is hashed to obtain the target address corresponding to the target information.
[0183] In one possible implementation of this application, the target information includes: type information, object information, and request parameter information;
[0184] Module 802: Used to perform hash calculations on the target information after conversion to a different base, to obtain the target address corresponding to the target information. Specifically, it includes:
[0185] If the request parameter information is greater than zero, the request parameter information is corrected according to the preset data correction parameters to obtain the corrected target request parameter information;
[0186] The sum of the type information, object information, and target request parameter information after conversion is calculated to obtain the target address corresponding to the target information.
[0187] In one possible implementation of this application, the calling module 803 is used to call the target processing function corresponding to the target address, specifically including:
[0188] Search a preset target item table, which stores addresses and functions with corresponding relationships;
[0189] Determine whether the target memory unit corresponding to the target address in the target item table is empty;
[0190] Based on the judgment result, perform the operation corresponding to the judgment result.
[0191] In one possible implementation of this application, the calling module 803 is used to perform an operation corresponding to the judgment result based on the judgment result, specifically including:
[0192] If the target memory unit corresponding to the target address in the target item table is not empty, then the target processing function within the target memory unit is called; or
[0193] If the target memory unit corresponding to the target address in the target item table is empty, then obtain the processing function corresponding to the USB device;
[0194] The address corresponding to each processing function is determined based on the function field information in each processing function;
[0195] Identify the processing function corresponding to the address that is the same as the target address as the target processing function, and call the target processing function;
[0196] The target item table is updated based on the correspondence between each address and the processing function.
[0197] In one possible implementation of this application, the calling module 803 is configured to determine the address corresponding to each of the processing functions based on the function field information in each of the processing functions, specifically including:
[0198] Extract the function field information corresponding to the independent variables in each of the processing functions, and determine the function target information corresponding to the function field information based on the correspondence between the function field information and the field information in the standard request corresponding to the processing function;
[0199] The target information corresponding to each processing function is hashed to obtain the target address corresponding to each processing function.
[0200] In one possible embodiment of this application, the apparatus further includes an entry update module and a calling module: after calling the target processing function corresponding to the target address, the entry update module further includes:
[0201] When it is detected that the number of first functions of the processing function corresponding to the USB device is different from the number of second functions of the processing function in the target item table, the function field information of each processing function corresponding to the USB device is obtained.
[0202] The address corresponding to each processing function is determined based on the function field information in each processing function;
[0203] The target item table is updated according to the correspondence between each address and each processing function.
[0204] In one possible embodiment of this application, the apparatus further includes an entry creation module, and a receiving and extraction module 801: before receiving a standard request sent by a host and extracting target information from the standard request based on field information in the standard request, the entry creation module further includes:
[0205] Obtain the processing function corresponding to the USB device and create a target table containing at least two memory units, wherein the number of memory units is greater than or equal to the number of processing functions;
[0206] Based on the function field information in each processing function, determine the function target information corresponding to each processing function;
[0207] Based on the function target information corresponding to each processing function, determine the target address corresponding to each processing function;
[0208] Store the target address and the corresponding target processing function in the target item table.
[0209] This application provides a communication request processing device, configured in a USB device. It receives a standard request sent by a host, extracts target information from the standard request based on field information, determines the target address based on the target information, and then calls the target processing function corresponding to the target address to process data in response to the standard request. This solution extracts target information from the request, determines the target address corresponding to the target processing function based on the target information, and then directly calls the corresponding target processing function based on the target address. This eliminates the need for a traversal search between the standard request and the processing function, reducing the computational load of the processing function search, improving the search efficiency of the processing function, and simultaneously reducing the program weight of the processing function search, saving memory, and thus improving the search performance of the processing function.
[0210] This invention also provides a USB device, such as... Figure 9 As shown, Figure 9 This is a schematic diagram of an embodiment of the USB device provided in this application.
[0211] The USB device integrates any of the communication request processing devices provided in the embodiments of the present invention. The USB device includes:
[0212] One or more processors;
[0213] Memory; and
[0214] One or more applications, wherein the applications are stored in memory and configured to be executed by a processor, wherein the steps of the communication request processing method in any of the embodiments described above are performed.
[0215] Specifically, a USB device may include components such as a processor 901 with one or more processing cores, a memory 902 with one or more computer-readable storage media, a power supply 903, and an input unit 904. Those skilled in the art will understand that... Figure 9The USB device structure shown does not constitute a limitation on the USB device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:
[0216] The processor 901 is the control center of the USB device. It connects various parts of the USB device via various interfaces and lines, and performs various functions and processes data by running or executing software programs and / or modules stored in the memory 902, and by calling data stored in the memory 902, thereby providing overall monitoring of the USB device. Optionally, the processor 901 may include one or more processing cores; preferably, the processor 901 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 901.
[0217] The memory 902 can be used to store software programs and modules. The processor 901 executes various functional applications and data processing by running the software programs and modules stored in the memory 902. The memory 902 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function, etc.; the data storage area may store data created based on the use of the USB device, etc. In addition, the memory 902 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 902 may also include a memory controller to provide the processor 901 with access to the memory 902.
[0218] In some embodiments of this application, the communication request processing apparatus can be implemented as a computer program, which can be implemented as follows: Figure 9 It runs on the USB device shown. The USB device's memory can store the various program modules that make up the processing device for the communication request, such as... Figure 8 The diagram shows a receiving / extraction module 801, a determining module 802, and a prompting / calling module 803. The computer program comprised of these modules causes the processor to execute the steps of the communication request processing methods described in the various embodiments of this application.
[0219] For example, Figure 9 The USB device shown can be accessed via, for example... Figure 8The receiving / extraction module 801 in the communication request processing apparatus shown executes step S201. The USB device can execute step S202 via the determining module 802. The USB device can execute step S203 via the prompting / calling module 803. The USB device includes a processor, memory, and a network interface connected via a system bus. The processor of the USB device provides computing and control capabilities. The memory of the USB device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the USB device is used for communication with external USB devices via a network connection. When the computer program is executed by the processor, it implements a communication request processing method.
[0220] The USB device also includes a power supply 903 that supplies power to the various components. Preferably, the power supply 903 is logically connected to the processor 901 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 903 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0221] The USB device may also include an input unit 904, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0222] Although not shown, a USB device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 901 in the USB device loads the executable files corresponding to the processes of one or more applications into the memory 902 according to the following instructions, and the processor 901 runs the applications stored in the memory 902 to realize various functions, as follows:
[0223] Receive standard requests sent by the host, and extract the target information from the standard requests based on the field information in the standard requests;
[0224] Determine the target address based on the target information;
[0225] The target processing function corresponding to the target address is invoked, and the data is processed in response to the standard request through the target processing function.
[0226] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0227] Therefore, embodiments of the present invention provide a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any of the communication request processing methods provided in the embodiments of the present invention. For example, the computer program loaded by the processor may execute the following steps:
[0228] Receive standard requests sent by the host, and extract the target information from the standard requests based on the field information in the standard requests;
[0229] Determine the target address based on the target information;
[0230] The target processing function corresponding to the target address is invoked, and the data is processed in response to the standard request through the target processing function.
[0231] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed descriptions of other embodiments above, which will not be repeated here.
[0232] In practice, each of the above units or structures can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units or structures, please refer to the previous method embodiments, which will not be repeated here.
[0233] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0234] The foregoing has provided a detailed description of a communication request processing method, apparatus, USB device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for processing communication requests, characterized in that, Applied to USB devices, the method includes: Receive a standard request sent by the host, and extract the target information from the standard request based on the field information in the standard request; the standard request includes the RequestType field, Request field, Value field, and Index field; Determine the target address based on the target information; The target processing function corresponding to the target address is invoked, and the target processing function responds to the standard request to perform data processing. The invocation of the target processing function corresponding to the target address includes: Search a preset target item table, which stores addresses and functions with corresponding relationships; If the target memory unit corresponding to the target address in the target item table is not empty, then the target processing function within the target memory unit is called; or If the target memory unit corresponding to the target address in the target item table is empty, then obtain the processing function corresponding to the USB device; The address corresponding to each processing function is determined based on the function field information in each processing function; Identify the processing function corresponding to the address that is the same as the target address as the target processing function, and call the target processing function; The target item table is updated based on the correspondence between each address and the processing function.
2. The method for processing communication requests according to claim 1, characterized in that, The target information includes type information, object information, and request parameter information, which are used to calculate the target address.
3. The method for processing communication requests according to claim 2, characterized in that, The step of extracting target information from the standard request based on field information in the standard request includes: Identify the request type field, request object field, and request parameter information field in the standard request; Extract the type information corresponding to the request type field, extract the object information corresponding to the request object field, and extract the request parameter information from the request parameter information field.
4. The method for processing communication requests according to claim 3, characterized in that, The step of extracting the object information corresponding to the request object field includes: Identify the bit value corresponding to the field of the requested object; Extract the bit value at a preset position from the bit value to obtain the object information corresponding to the request object field.
5. The method for processing communication requests according to any one of claims 2-4, characterized in that, Determining the target address based on the target information includes: The binary request parameter information in the target information is converted into the target base request parameter information to obtain the target information after conversion. The target information after conversion to a different base is hashed to obtain the target address corresponding to the target information.
6. The method for processing communication requests according to claim 5, characterized in that, The target information after conversion to a different base is hashed to obtain the target address corresponding to the target information, including: If the request parameter information is greater than zero, the request parameter information is corrected according to the preset data correction parameters to obtain the corrected target request parameter information; The sum of the type information, object information, and target request parameter information after conversion is calculated to obtain the target address corresponding to the target information.
7. The method for processing communication requests according to claim 1, characterized in that, The step of determining the address corresponding to each processing function based on the function field information in each processing function includes: Extract the function field information corresponding to the independent variables in each of the processing functions, and determine the function target information corresponding to the function field information based on the correspondence between the function field information and the field information in the standard request corresponding to the processing function; The target information corresponding to each processing function is hashed to obtain the target address corresponding to each processing function.
8. The method for processing communication requests according to claim 1 or 7, characterized in that, After invoking the target processing function corresponding to the target address, the method further includes: When it is detected that the number of first functions of the processing function corresponding to the USB device is different from the number of second functions of the processing function in the target item table, the function field information of each processing function corresponding to the USB device is obtained. The address corresponding to each processing function is determined based on the function field information in each processing function; The target item table is updated according to the correspondence between each address and each processing function.
9. The method for processing communication requests according to claim 1 or 7, characterized in that, Before receiving the standard request sent by the host and extracting the target information from the standard request based on the field information in the standard request, the method further includes: Obtain the processing function corresponding to the USB device, and create a target item table including at least two memory units; Based on the function field information in each of the processing functions, determine the function target information corresponding to each processing function; Based on the function target information corresponding to each of the processing functions, determine the target address corresponding to each of the processing functions; The target address and the corresponding target processing function are stored in the target item table.
10. A processing apparatus for a communication request, characterized in that, Applied to USB devices, the communication request processing apparatus includes: Receiving and Extraction Module: Used to receive standard requests sent by the host, and extract target information from the standard requests based on the field information in the standard requests; the standard requests include RequestType field, Request field, Value field, and Index field; Determining module: used to determine the target address based on the target information; The calling module is used to call the target processing function corresponding to the target address, and to respond to the standard request and perform data processing through the target processing function; to search a preset target item table, which stores addresses and functions with corresponding relationships; if the target memory unit corresponding to the target address in the target item table is not empty, then the target processing function in the target memory unit is called; or if the target memory unit corresponding to the target address in the target item table is empty, then the processing function corresponding to the USB device is obtained; based on the function field information in each processing function, the address corresponding to each processing function is determined; the processing function corresponding to the address that is the same as the target address is determined as the target processing function, and the target processing function is called; and the target item table is updated according to the correspondence between each address and the processing function.
11. A USB device, characterized in that, The USB device includes: One or more processors; Memory; and One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the processing method of the communication request according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that, It stores a computer program, which is loaded by a processor to perform the steps of the communication request processing method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Small size computer system interface command processing method and equipment
CN1889034A