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