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 /**   Host Stack                                                          */
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_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_stack_interface_set                        PORTABLE C      */
37 /*                                                           6.1.12       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function performs a setting of an alternate setting for a      */
45 /*    specific interface.                                                 */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    interface                             Pointer to interface          */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    Completion Status                                                   */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _ux_host_stack_hcd_transfer_request   HCD transfer request          */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    USBX Components                                                     */
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 /*                                            resulting in version 6.1    */
70 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            added standalone support,   */
72 /*                                            resulting in version 6.1.10 */
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_host_stack_interface_set(UX_INTERFACE * interface_ptr)79 UINT  _ux_host_stack_interface_set(UX_INTERFACE *interface_ptr)
80 {
81 
82 UX_DEVICE               *device;
83 UX_CONFIGURATION        *configuration;
84 UX_TRANSFER             *transfer_request;
85 UINT                    status;
86 UX_ENDPOINT             *control_endpoint;
87 
88     /* If trace is enabled, insert this event into the trace buffer.  */
89     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_INTERFACE_SET, interface_ptr, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
90 
91     /* Retrieve the pointer to the control endpoint and its transfer_request.
92        From the interface we go back to the configuration, then the device.
93        The device contains the default control endpoint container.  */
94     configuration =     interface_ptr -> ux_interface_configuration;
95     device =            configuration -> ux_configuration_device;
96     control_endpoint =  &device -> ux_device_control_endpoint;
97     transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
98 
99     /* Create a transfer_request for the SET_INTERFACE request. No data for this request */
100     transfer_request -> ux_transfer_request_requested_length =  0;
101     transfer_request -> ux_transfer_request_function =          UX_SET_INTERFACE;
102     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_INTERFACE;
103     transfer_request -> ux_transfer_request_index =             (USHORT) interface_ptr -> ux_interface_descriptor.bInterfaceNumber;
104     transfer_request -> ux_transfer_request_value =             (USHORT) interface_ptr -> ux_interface_descriptor.bAlternateSetting;
105 
106     /* Send request.  */
107     status = _ux_host_stack_transfer_request(transfer_request);
108 
109     /* Return status completion.  */
110     return(status);
111 }
112 
113