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