1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
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 |
|
|
/**************************************************************************/ |
65 |
|
5 |
UINT _ux_device_stack_alternate_setting_get(ULONG interface_value) |
66 |
|
|
{ |
67 |
|
|
|
68 |
|
|
UX_SLAVE_TRANSFER *transfer_request; |
69 |
|
|
UX_SLAVE_INTERFACE *interface_ptr; |
70 |
|
|
UX_SLAVE_DEVICE *device; |
71 |
|
|
UX_SLAVE_ENDPOINT *endpoint; |
72 |
|
|
UINT status; |
73 |
|
|
|
74 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
75 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_ALTERNATE_SETTING_GET, interface_value, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0) |
76 |
|
|
|
77 |
|
|
/* Get the pointer to the device. */ |
78 |
|
5 |
device = &_ux_system_slave -> ux_system_slave_device; |
79 |
|
|
|
80 |
|
|
/* If the device was in the configured state, there may be interfaces |
81 |
|
|
attached to the configuration. */ |
82 |
✓✓ |
5 |
if (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED) |
83 |
|
|
{ |
84 |
|
|
|
85 |
|
|
/* Obtain the pointer to the first interface attached. */ |
86 |
|
4 |
interface_ptr = device -> ux_slave_device_first_interface; |
87 |
|
|
|
88 |
|
|
#if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1 |
89 |
|
|
/* Start parsing each interface. */ |
90 |
✓✓ |
5 |
while (interface_ptr != UX_NULL) |
91 |
|
|
#else |
92 |
|
|
if (interface_ptr != UX_NULL) |
93 |
|
|
#endif |
94 |
|
|
{ |
95 |
|
|
|
96 |
|
|
/* Check if this is the interface we have an inquiry for. */ |
97 |
✓✓ |
4 |
if (interface_ptr -> ux_slave_interface_descriptor.bInterfaceNumber == interface_value) |
98 |
|
|
{ |
99 |
|
|
|
100 |
|
|
/* Get the control endpoint of the device. */ |
101 |
|
3 |
endpoint = &device -> ux_slave_device_control_endpoint; |
102 |
|
|
|
103 |
|
|
/* Get the pointer to the transfer request associated with the endpoint. */ |
104 |
|
3 |
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request; |
105 |
|
|
|
106 |
|
|
/* Set the value of the alternate setting in the buffer. */ |
107 |
|
3 |
*transfer_request -> ux_slave_transfer_request_data_pointer = |
108 |
|
3 |
(UCHAR) interface_ptr -> ux_slave_interface_descriptor.bAlternateSetting; |
109 |
|
|
|
110 |
|
|
/* Setup the length appropriately. */ |
111 |
|
3 |
transfer_request -> ux_slave_transfer_request_requested_length = 1; |
112 |
|
|
|
113 |
|
|
/* Set the phase of the transfer to data out. */ |
114 |
|
3 |
transfer_request -> ux_slave_transfer_request_phase = UX_TRANSFER_PHASE_DATA_OUT; |
115 |
|
|
|
116 |
|
|
/* Send the descriptor with the appropriate length to the host. */ |
117 |
|
3 |
status = _ux_device_stack_transfer_request(transfer_request, 1, 1); |
118 |
|
|
|
119 |
|
|
/* Return the function status. */ |
120 |
|
3 |
return(status); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
#if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) || UX_MAX_DEVICE_INTERFACES > 1 |
124 |
|
|
/* Get the next interface. */ |
125 |
|
1 |
interface_ptr = interface_ptr -> ux_slave_interface_next_interface; |
126 |
|
|
#endif |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/* Return error completion. */ |
131 |
|
2 |
return(UX_ERROR); |
132 |
|
|
} |
133 |
|
|
|