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 /** Device Stack */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define UX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "ux_api.h"
29 #include "ux_device_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_device_stack_alternate_setting_get PORTABLE C */
37 /* 6.1.12 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function gets the alternate setting for a specific interface. */
45 /* */
46 /* INPUT */
47 /* */
48 /* endpoint Pointer to endpoint */
49 /* interface_value Interface value */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_device_stack_transfer_request Process transfer request */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* Application */
62 /* Device Stack */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
70 /* optimized based on compile */
71 /* definitions, */
72 /* resulting in version 6.1 */
73 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
74 /* fixed parameter/variable */
75 /* names conflict C++ keyword, */
76 /* resulting in version 6.1.12 */
77 /* */
78 /**************************************************************************/
_ux_device_stack_alternate_setting_get(ULONG interface_value)79 UINT _ux_device_stack_alternate_setting_get(ULONG interface_value)
80 {
81
82 UX_SLAVE_TRANSFER *transfer_request;
83 UX_SLAVE_INTERFACE *interface_ptr;
84 UX_SLAVE_DEVICE *device;
85 UX_SLAVE_ENDPOINT *endpoint;
86 UINT status;
87
88 /* If trace is enabled, insert this event into the trace buffer. */
89 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_ALTERNATE_SETTING_GET, interface_value, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
90
91 /* Get the pointer to the device. */
92 device = &_ux_system_slave -> ux_system_slave_device;
93
94 /* If the device was in the configured state, there may be interfaces
95 attached to the configuration. */
96 if (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED)
97 {
98
99 /* Obtain the pointer to the first interface attached. */
100 interface_ptr = device -> ux_slave_device_first_interface;
101
102 #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
103 /* Start parsing each interface. */
104 while (interface_ptr != UX_NULL)
105 #else
106 if (interface_ptr != UX_NULL)
107 #endif
108 {
109
110 /* Check if this is the interface we have an inquiry for. */
111 if (interface_ptr -> ux_slave_interface_descriptor.bInterfaceNumber == interface_value)
112 {
113
114 /* Get the control endpoint of the device. */
115 endpoint = &device -> ux_slave_device_control_endpoint;
116
117 /* Get the pointer to the transfer request associated with the endpoint. */
118 transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
119
120 /* Set the value of the alternate setting in the buffer. */
121 *transfer_request -> ux_slave_transfer_request_data_pointer =
122 (UCHAR) interface_ptr -> ux_slave_interface_descriptor.bAlternateSetting;
123
124 /* Setup the length appropriately. */
125 transfer_request -> ux_slave_transfer_request_requested_length = 1;
126
127 /* Set the phase of the transfer to data out. */
128 transfer_request -> ux_slave_transfer_request_phase = UX_TRANSFER_PHASE_DATA_OUT;
129
130 /* Send the descriptor with the appropriate length to the host. */
131 status = _ux_device_stack_transfer_request(transfer_request, 1, 1);
132
133 /* Return the function status. */
134 return(status);
135 }
136
137 #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
138 /* Get the next interface. */
139 interface_ptr = interface_ptr -> ux_slave_interface_next_interface;
140 #endif
141 }
142 }
143
144 /* Return error completion. */
145 return(UX_ERROR);
146 }
147
148