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