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_create PORTABLE C */
36 /* 6.2.0 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function will create a configuration instance. It scan all the */
44 /* interfaces hooked to the configuration and enable each interface */
45 /* with the alternate setting 0. */
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_create Create 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_create(UX_CONFIGURATION * configuration)80 UINT _ux_host_stack_configuration_instance_create(UX_CONFIGURATION *configuration)
81 {
82
83 UX_INTERFACE *interface_ptr;
84 UINT status;
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_CREATE, 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 /* Each selected alternate setting 0 for each interface must be created. */
93 while (interface_ptr != UX_NULL)
94 {
95
96 /* Check if we are dealing with the first alternate setting. */
97 if (interface_ptr -> ux_interface_descriptor.bAlternateSetting == 0)
98 {
99
100 #if UX_HOST_STACK_CONFIGURATION_INSTANCE_CREATE_CONTROL == UX_HOST_STACK_CONFIGURATION_INSTANCE_CREATE_OWNED
101
102 /* Create the interface, if it's usable. */
103 if (interface_ptr -> ux_interface_class || configuration -> ux_configuration_device -> ux_device_class)
104 #endif
105 {
106 status = _ux_host_stack_interface_instance_create(interface_ptr);
107
108 /* Check status, the controller may have refused the endpoint creation. */
109 if (status != UX_SUCCESS)
110
111 /* An error occurred. The interface cannot be mounted. */
112 return(status);
113 }
114 }
115
116 /* Next interface. */
117 interface_ptr = interface_ptr -> ux_interface_next_interface;
118 }
119
120 /* Return successful completion. */
121 return(UX_SUCCESS);
122 }
123
124