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_configuration_instance_delete        PORTABLE C      */
37 /*                                                           6.2.0        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function will delete a configuration instance. It does not     */
45 /*    delete configuration container but it deletes all the alternate     */
46 /*    current alternate settings for each interface it owns.              */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    configuration                         Pointer to configuration      */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _ux_host_stack_interface_instance_delete  Delete interface instance */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    USBX Components                                                     */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
69 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
72 /*                                            fixed parameter/variable    */
73 /*                                            names conflict C++ keyword, */
74 /*                                            resulting in version 6.1.12 */
75 /*  10-31-2022     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            added interface instance    */
77 /*                                            creation strategy control,  */
78 /*                                            resulting in version 6.2.0  */
79 /*                                                                        */
80 /**************************************************************************/
_ux_host_stack_configuration_instance_delete(UX_CONFIGURATION * configuration)81 VOID  _ux_host_stack_configuration_instance_delete(UX_CONFIGURATION *configuration)
82 {
83 
84 UX_INTERFACE    *interface_ptr;
85 ULONG           current_alternate_setting;
86 
87     /* If trace is enabled, insert this event into the trace buffer.  */
88     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CONFIGURATION_INSTANCE_DELETE, configuration, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
89 
90     /* Obtain the first interface for this configuration.  */
91     interface_ptr =  configuration -> ux_configuration_first_interface;
92 
93     /* In order to keep the compiler happy, we reset the alternate setting.  */
94     current_alternate_setting =  0;
95 
96     /* Each selected alternate setting for each interface must be deleted.  */
97     while (interface_ptr != UX_NULL)
98     {
99 
100         /* If this is the first alternate setting, the current alternate setting is maintained here.  */
101         if (interface_ptr -> ux_interface_descriptor.bAlternateSetting == 0)
102         {
103 
104             current_alternate_setting =  interface_ptr -> ux_interface_current_alternate_setting;
105         }
106 
107         if (interface_ptr -> ux_interface_descriptor.bAlternateSetting == current_alternate_setting)
108         {
109 
110 #if UX_HOST_STACK_CONFIGURATION_INSTANCE_CREATE_CONTROL == UX_HOST_STACK_CONFIGURATION_INSTANCE_CREATE_OWNED
111 
112             /* If interface is usable, remove physical creates.  */
113             if (interface_ptr -> ux_interface_class || configuration -> ux_configuration_device -> ux_device_class)
114 #endif
115                 _ux_host_stack_interface_instance_delete(interface_ptr);
116         }
117 
118         interface_ptr =  interface_ptr -> ux_interface_next_interface;
119     }
120 
121     return;
122 }
123 
124