1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Device Stack */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define UX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "ux_api.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_stack_interface_get PORTABLE C */
36 /* 6.1.12 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function is deprecated, ux_device_stack_alternate_setting_get */
44 /* does the same thing and used by the core stack. */
45 /* */
46 /* This function gets the current alternate setting for an interface. */
47 /* */
48 /* INPUT */
49 /* */
50 /* interface_value Value of the interface */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Completion Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* (ux_slave_dcd_function) DCD dispatch function */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application */
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_interface_get(UINT interface_value)79 UINT _ux_device_stack_interface_get(UINT interface_value)
80 {
81
82 UX_SLAVE_DCD *dcd;
83 UX_SLAVE_TRANSFER *transfer_request;
84 UX_SLAVE_INTERFACE *interface_ptr;
85 UX_SLAVE_DEVICE *device;
86 UX_SLAVE_ENDPOINT *endpoint;
87 UINT status;
88
89 /* If trace is enabled, insert this event into the trace buffer. */
90 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_INTERFACE_GET, interface_value, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0)
91
92 /* Get the pointer to the DCD. */
93 dcd = &_ux_system_slave -> ux_system_slave_dcd;
94
95 /* Get the pointer to the device. */
96 device = &_ux_system_slave -> ux_system_slave_device;
97
98 /* Get the control endpoint for the device. */
99 endpoint = &device -> ux_slave_device_control_endpoint;
100
101 /* If the device was in the configured state, there may be interfaces
102 attached to the configuration. */
103 if (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED)
104 {
105
106 /* Get the pointer to the first interface. */
107 interface_ptr = device -> ux_slave_device_first_interface;
108
109 #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
110 /* Parse the interfaces if any. */
111 while (interface_ptr != UX_NULL)
112 {
113 #endif
114
115 /* Check if this is the interface we have an inquiry for. */
116 if (interface_ptr -> ux_slave_interface_descriptor.bInterfaceNumber == interface_value)
117 {
118
119 /* Get the pointer to the transfer request associated with the endpoint. */
120 transfer_request = &endpoint -> ux_slave_endpoint_transfer_request;
121
122 /* Set the value of the alternate setting in the buffer. */
123 *transfer_request -> ux_slave_transfer_request_data_pointer =
124 (UCHAR) interface_ptr -> ux_slave_interface_descriptor.bAlternateSetting;
125
126 /* Setup the length appropriately. */
127 transfer_request -> ux_slave_transfer_request_requested_length = 1;
128
129 /* Set the phase of the transfer to data out. */
130 transfer_request -> ux_slave_transfer_request_phase = UX_TRANSFER_PHASE_DATA_OUT;
131
132 /* Send the descriptor with the appropriate length to the host. */
133 status = dcd -> ux_slave_dcd_function(dcd, UX_DCD_TRANSFER_REQUEST, transfer_request);
134
135 /* Return the function status code. */
136 return(status);
137 }
138
139 #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1
140 /* Get the next interface. */
141 interface_ptr = interface_ptr -> ux_slave_interface_next_interface;
142 }
143 #endif
144
145 }
146
147 /* The alternate setting value was not found, so we return a stall error. */
148 dcd -> ux_slave_dcd_function(dcd, UX_DCD_STALL_ENDPOINT, endpoint);
149
150 /* Return the status to the caller. */
151 return(UX_ERROR);
152 }
153
154