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_interface_get PORTABLE C */
37 /* 6.1.12 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function is deprecated, ux_device_stack_alternate_setting_get */
45 /* does the same thing and used by the core stack. */
46 /* */
47 /* This function gets the current alternate setting for an interface. */
48 /* */
49 /* INPUT */
50 /* */
51 /* interface_value Value of the interface */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* (ux_slave_dcd_function) DCD dispatch function */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
70 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
71 /* optimized based on compile */
72 /* definitions, */
73 /* resulting in version 6.1 */
74 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
75 /* fixed parameter/variable */
76 /* names conflict C++ keyword, */
77 /* resulting in version 6.1.12 */
78 /* */
79 /**************************************************************************/
_ux_device_stack_interface_get(UINT interface_value)80 UINT _ux_device_stack_interface_get(UINT interface_value)
81 {
82
83 UX_SLAVE_DCD *dcd;
84 UX_SLAVE_TRANSFER *transfer_request;
85 UX_SLAVE_INTERFACE *interface_ptr;
86 UX_SLAVE_DEVICE *device;
87 UX_SLAVE_ENDPOINT *endpoint;
88 UINT status;
89
90 /* If trace is enabled, insert this event into the trace buffer. */
91 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_INTERFACE_GET, interface_value, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
92
93 /* Get the pointer to the DCD. */
94 dcd = &_ux_system_slave -> ux_system_slave_dcd;
95
96 /* Get the pointer to the device. */
97 device = &_ux_system_slave -> ux_system_slave_device;
98
99 /* Get the control endpoint for the device. */
100 endpoint = &device -> ux_slave_device_control_endpoint;
101
102 /* If the device was in the configured state, there may be interfaces
103 attached to the configuration. */
104 if (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED)
105 {
106
107 /* Get the pointer to the first interface. */
108 interface_ptr = device -> ux_slave_device_first_interface;
109
110 #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
111 /* Parse the interfaces if any. */
112 while (interface_ptr != UX_NULL)
113 {
114 #endif
115
116 /* Check if this is the interface we have an inquiry for. */
117 if (interface_ptr -> ux_slave_interface_descriptor.bInterfaceNumber == interface_value)
118 {
119
120 /* Get the pointer to the transfer request associated with the endpoint. */
121 transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
122
123 /* Set the value of the alternate setting in the buffer. */
124 *transfer_request -> ux_slave_transfer_request_data_pointer =
125 (UCHAR) interface_ptr -> ux_slave_interface_descriptor.bAlternateSetting;
126
127 /* Setup the length appropriately. */
128 transfer_request -> ux_slave_transfer_request_requested_length = 1;
129
130 /* Set the phase of the transfer to data out. */
131 transfer_request -> ux_slave_transfer_request_phase = UX_TRANSFER_PHASE_DATA_OUT;
132
133 /* Send the descriptor with the appropriate length to the host. */
134 status = dcd -> ux_slave_dcd_function(dcd, UX_DCD_TRANSFER_REQUEST, transfer_request);
135
136 /* Return the function status code. */
137 return(status);
138 }
139
140 #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
141 /* Get the next interface. */
142 interface_ptr = interface_ptr -> ux_slave_interface_next_interface;
143 }
144 #endif
145
146 }
147
148 /* The alternate setting value was not found, so we return a stall error. */
149 dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);
150
151 /* Return the status to the caller. */
152 return(UX_ERROR);
153 }
154
155