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 /**   Device Stack                                                        */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_device_stack.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_stack_interface_start                    PORTABLE C      */
36 /*                                                           6.1.12       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function starts an interface associated with the enabled       */
44 /*    configuration.                                                      */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    interface                             Pointer to interface          */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    Completion Status                                                   */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    (ux_slave_class_entry_function)       Device class entry function   */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Application                                                         */
61 /*    Device Stack                                                        */
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 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            fixed parameter/variable    */
72 /*                                            names conflict C++ keyword, */
73 /*                                            resulting in version 6.1.12 */
74 /*                                                                        */
75 /**************************************************************************/
_ux_device_stack_interface_start(UX_SLAVE_INTERFACE * interface_ptr)76 UINT  _ux_device_stack_interface_start(UX_SLAVE_INTERFACE *interface_ptr)
77 {
78 
79 UX_SLAVE_DEVICE             *device;
80 UX_SLAVE_CLASS              *class_ptr;
81 UINT                        status;
82 UX_SLAVE_CLASS_COMMAND      class_command;
83 
84 
85     /* Get the class for the interface.  */
86     class_ptr =  _ux_system_slave -> ux_system_slave_interface_class_array[interface_ptr -> ux_slave_interface_descriptor.bInterfaceNumber];
87 
88     /* Check if class driver is available. */
89     if (class_ptr == UX_NULL)
90 
91         /* There is no class driver supported. */
92         return (UX_NO_CLASS_MATCH);
93 
94     /* Get the pointer to the device.  */
95     device =  &_ux_system_slave -> ux_system_slave_device;
96 
97     /* Build all the fields of the Class Command.  */
98     class_command.ux_slave_class_command_request   =    UX_SLAVE_CLASS_COMMAND_QUERY;
99     class_command.ux_slave_class_command_interface =   (VOID *)interface_ptr;
100     class_command.ux_slave_class_command_class     =   interface_ptr -> ux_slave_interface_descriptor.bInterfaceClass;
101     class_command.ux_slave_class_command_subclass  =   interface_ptr -> ux_slave_interface_descriptor.bInterfaceSubClass;
102     class_command.ux_slave_class_command_protocol  =   interface_ptr -> ux_slave_interface_descriptor.bInterfaceProtocol;
103     class_command.ux_slave_class_command_vid       =   device -> ux_slave_device_descriptor.idVendor;
104     class_command.ux_slave_class_command_pid       =   device -> ux_slave_device_descriptor.idProduct;
105 
106     /* We can now memorize the interface pointer associated with this class.  */
107     class_ptr -> ux_slave_class_interface = interface_ptr;
108 
109     /* We have found a potential candidate. Call this registered class entry function.  */
110     status = class_ptr -> ux_slave_class_entry_function(&class_command);
111 
112     /* The status tells us if the registered class wants to own this class.  */
113     if (status == UX_SUCCESS)
114     {
115 
116         /* Store the class container. */
117         class_command.ux_slave_class_command_class_ptr =  class_ptr;
118 
119         /* Store the command.  */
120         class_command.ux_slave_class_command_request =  UX_SLAVE_CLASS_COMMAND_ACTIVATE;
121 
122         /* Activate the class.  */
123         status = class_ptr -> ux_slave_class_entry_function(&class_command);
124 
125         /* If the class was successfully activated, set the class for the interface.  */
126         if(status == UX_SUCCESS)
127             interface_ptr -> ux_slave_interface_class =  class_ptr;
128 
129         return(status);
130     }
131 
132     /* There is no driver who want to own this class!  */
133     return(UX_NO_CLASS_MATCH);
134 }
135 
136