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 /** HUB Class */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /* Include necessary system files. */
24
25 #define UX_SOURCE_CODE
26
27 #include "ux_api.h"
28 #include "ux_host_class_hub.h"
29 #include "ux_host_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_host_class_hub_feature PORTABLE C */
37 /* 6.1.12 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function will send a command to the HUB on a specific port. */
45 /* The commands can be SET_FEATURE or CLEAR_FEATURE. */
46 /* */
47 /* In standalone mode, this functioin prepares the control transfer */
48 /* request context of specific command, for host stack transfer */
49 /* function to process, in next steps. */
50 /* */
51 /* INPUT */
52 /* */
53 /* hub Pointer to HUB class */
54 /* port Port number */
55 /* command Command to send */
56 /* feature Feature to send */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* Completion Status */
61 /* */
62 /* CALLS */
63 /* */
64 /* _ux_host_stack_transfer_request Process transfer request */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* HUB Class */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
75 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
76 /* resulting in version 6.1 */
77 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
78 /* added standalone support, */
79 /* resulting in version 6.1.12 */
80 /* */
81 /**************************************************************************/
_ux_host_class_hub_feature(UX_HOST_CLASS_HUB * hub,UINT port,UINT command,UINT function)82 UINT _ux_host_class_hub_feature(UX_HOST_CLASS_HUB *hub, UINT port, UINT command, UINT function)
83 {
84
85 UX_ENDPOINT *control_endpoint;
86 UX_TRANSFER *transfer_request;
87 UINT target;
88 UINT status;
89
90
91 /* We need to get the default control endpoint transfer request pointer. */
92 control_endpoint = &hub -> ux_host_class_hub_device -> ux_device_control_endpoint;
93 transfer_request = &control_endpoint -> ux_endpoint_transfer_request;
94
95 /* The target is DEVICE for the HUB and OTHER for the downstream ports. */
96 if (port == 0)
97 target = UX_REQUEST_TARGET_DEVICE;
98 else
99 target = UX_REQUEST_TARGET_OTHER;
100
101 /* Create a transfer request for the SET_FEATURE or CLEAR_FEATURE request. */
102 transfer_request -> ux_transfer_request_function = command;
103 transfer_request -> ux_transfer_request_requested_length = 0;
104 transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | target;
105 transfer_request -> ux_transfer_request_value = function;
106 transfer_request -> ux_transfer_request_index = port;
107
108 #if defined(UX_HOST_STANDALONE)
109
110 /* Reset transfer state for _run. */
111 UX_TRANSFER_STATE_RESET(transfer_request);
112 status = UX_SUCCESS;
113 #else
114
115 /* Send request to HCD layer. */
116 status = _ux_host_stack_transfer_request(transfer_request);
117 #endif
118
119 /* Return completion status. */
120 return(status);
121 }
122