1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Host Stack */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /* Include necessary system files. */
25
26 #define UX_SOURCE_CODE
27
28 #include "ux_api.h"
29 #include "ux_host_stack.h"
30
31
32 #if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DISABLE)
33 #if defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_VIDPID_DISABLE) && \
34 defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DCSP_DISABLE)
35 #error When device driver scan is enabled at least one of scan method must be enabled in (VIDPID, DeviceClassSubclassProtocol)
36 #endif
37 #endif
38
39 /**************************************************************************/
40 /* */
41 /* FUNCTION RELEASE */
42 /* */
43 /* _ux_host_stack_class_device_scan PORTABLE C */
44 /* 6.1.10 */
45 /* AUTHOR */
46 /* */
47 /* Chaoqiong Xiao, Microsoft Corporation */
48 /* */
49 /* DESCRIPTION */
50 /* */
51 /* This function will scan all registered classes with a device */
52 /* candidate. Priority is given to the PID/VID and then the */
53 /* Class/Subclass/Protocol. */
54 /* */
55 /* INPUT */
56 /* */
57 /* device Pointer to device */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* Completion Status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _ux_host_stack_class_call Call host stack class */
66 /* (ux_host_class_entry_function) Class entry function */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* USBX Components */
71 /* */
72 /* RELEASE HISTORY */
73 /* */
74 /* DATE NAME DESCRIPTION */
75 /* */
76 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
77 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
78 /* used query usage of device */
79 /* ClassSubclassProtocol, */
80 /* resulting in version 6.1 */
81 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */
82 /* removed duplicate line, */
83 /* resulting in version 6.1.7 */
84 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
85 /* added standalone support, */
86 /* resulting in version 6.1.10 */
87 /* */
88 /**************************************************************************/
_ux_host_stack_class_device_scan(UX_DEVICE * device)89 UINT _ux_host_stack_class_device_scan(UX_DEVICE *device)
90 {
91 #if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DISABLE)
92
93 UINT status;
94 UX_HOST_CLASS *class_inst = UX_NULL;
95 UX_HOST_CLASS_COMMAND class_command;
96
97 /* Perform the command initialization. */
98 class_command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_QUERY;
99 class_command.ux_host_class_command_container = (VOID *) device;
100 class_command.ux_host_class_command_vid = device -> ux_device_descriptor.idVendor;
101 class_command.ux_host_class_command_pid = device -> ux_device_descriptor.idProduct;
102 class_command.ux_host_class_command_class = device -> ux_device_descriptor.bDeviceClass;
103 class_command.ux_host_class_command_subclass = device -> ux_device_descriptor.bDeviceSubClass;
104 class_command.ux_host_class_command_protocol = device -> ux_device_descriptor.bDeviceProtocol;
105 class_command.ux_host_class_command_iad_class = 0;
106 class_command.ux_host_class_command_iad_subclass = 0;
107 class_command.ux_host_class_command_iad_protocol = 0;
108
109 #if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_VIDPID_DISABLE)
110 /* We start with the PID/VID for this device. */
111 class_command.ux_host_class_command_usage = UX_HOST_CLASS_COMMAND_USAGE_PIDVID;
112 class_inst = _ux_host_stack_class_call(&class_command);
113 #endif
114
115 #if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DCSP_DISABLE)
116 /* On return, either we have found a class or the device is still an orphan. */
117 if (class_inst == UX_NULL)
118 {
119
120 /* It the PID/VID did not work, we continue looking for the Class\Subclass\Protocol match. */
121 class_command.ux_host_class_command_usage = UX_HOST_CLASS_COMMAND_USAGE_DCSP;
122 class_inst = _ux_host_stack_class_call(&class_command);
123
124 }
125 #endif
126
127 /* On return, either we have found a class or the device is still an orphan. */
128 if (class_inst != UX_NULL)
129 {
130
131 device -> ux_device_class = class_inst;
132
133 #if defined(UX_HOST_STANDALONE)
134
135 /* Activation may take time, run as state machine. */
136 status = UX_SUCCESS;
137 return(status);
138 #else
139 class_command.ux_host_class_command_class_ptr = class_inst;
140 class_command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE;
141 status = device -> ux_device_class -> ux_host_class_entry_function(&class_command);
142
143 /* Return result of activation. */
144 return(status);
145 #endif
146 }
147
148 #endif
149
150 /* Return an error. */
151 return(UX_NO_CLASS_MATCH);
152 }
153
154