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