GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_configuration_interface_get.c Lines: 25 29 86.2 %
Date: 2026-03-06 18:57:10 Branches: 16 20 80.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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_interface_get          PORTABLE C      */
37
/*                                                           6.1.12       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function returns an interface container based on a             */
45
/*    configuration handle, an interface index and an alternate setting   */
46
/*    index.                                                              */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    configuration                         Pointer to configuration      */
51
/*    interface_index                       Index of interface            */
52
/*    alternate_setting_index               Index of alternate setting    */
53
/*    interface                             Destination of interface      */
54
/*                                            pointer                     */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    Completion Status                                                   */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    None                                                                */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application                                                         */
67
/*    USBX Components                                                     */
68
/*                                                                        */
69
/**************************************************************************/
70
79
UINT  _ux_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration,
71
                                                UINT interface_index, UINT alternate_setting_index,
72
                                                UX_INTERFACE **ux_interface)
73
{
74
75
UINT                current_interface_number;
76
UINT                container_index;
77
UX_INTERFACE        *current_interface;
78
79
80
    /* Do a sanity check on the configuration handle.  */
81
79
    if (configuration -> ux_configuration_handle != (ULONG) (ALIGN_TYPE) configuration)
82
    {
83
84
        /* If trace is enabled, insert this event into the trace buffer.  */
85
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0)
86
87
1
        return(UX_CONFIGURATION_HANDLE_UNKNOWN);
88
    }
89
90
    /* Start with the interface attached to the configuration.  */
91
78
    current_interface =  configuration -> ux_configuration_first_interface;
92
93
    /* The first interface has the index 0 */
94
78
    container_index =  0;
95
96
    /* Reset the interface number */
97
78
    current_interface_number =  0;
98
99
    /* Traverse the list of the interfaces until we found the right one */
100
164
    while (current_interface != UX_NULL)
101
    {
102
103
        /* Check if the interface index matches the current one.  */
104
83
        if (interface_index == container_index)
105
        {
106
107
            /* We have found the correct interface, now search for the alternate setting.  */
108
76
            current_interface_number =  current_interface -> ux_interface_descriptor.bInterfaceNumber;
109
110
            /* The first alternate setting has the index 0.  */
111
76
            container_index =  0;
112
113
            /* Loop on all the alternate settings for this interface.  */
114
78
            while (current_interface != UX_NULL)
115
            {
116
117
                /* Check if the index is matched */
118
77
                if (alternate_setting_index == container_index)
119
                {
120
121
                    /* We have found the right interface/alternate setting combination. Set the
122
                       interface return pointer.  */
123
74
                    *ux_interface =  current_interface;
124
125
                    /* Return success to caller.  */
126
74
                    return(UX_SUCCESS);
127
                }
128
129
                /* Move to next alternate setting index.  */
130
3
                container_index++;
131
132
                /* Move to the next alternate setting.   */
133
3
                current_interface =  current_interface -> ux_interface_next_interface;
134
135
136
                /* Check new interface pointer, might be the end.  */
137
3
                if (current_interface != UX_NULL)
138
                {
139
140
                    /* And verify that we are still in the same interface.  */
141
2
                    if (current_interface -> ux_interface_descriptor.bInterfaceNumber != current_interface_number)
142
                    {
143
144
                        /* Error trap. */
145
1
                        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_INTERFACE_HANDLE_UNKNOWN);
146
147
                        /* If trace is enabled, insert this event into the trace buffer.  */
148
                        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_INTERFACE_HANDLE_UNKNOWN, ux_interface, 0, 0, UX_TRACE_ERRORS, 0, 0)
149
150
1
                        return(UX_INTERFACE_HANDLE_UNKNOWN);
151
                    }
152
                }
153
            }
154
        }
155
156
        /* Check the current interface, we may already be at the end ... */
157
8
        if (current_interface != UX_NULL)
158
        {
159
160
            /* Move to the next interface.  */
161
7
            current_interface =  current_interface -> ux_interface_next_interface;
162
163
            /* Move to the next interface index. */
164
7
            container_index++;
165
        }
166
    }
167
168
    /* Error trap. */
169
3
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_INTERFACE_HANDLE_UNKNOWN);
170
171
    /* If trace is enabled, insert this event into the trace buffer.  */
172
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_INTERFACE_HANDLE_UNKNOWN, ux_interface, 0, 0, UX_TRACE_ERRORS, 0, 0)
173
174
    /* Didn't find the right interface/alternate setting, return an error!  */
175
3
    return(UX_INTERFACE_HANDLE_UNKNOWN);
176
}
177
178
179
/**************************************************************************/
180
/*                                                                        */
181
/*  FUNCTION                                               RELEASE        */
182
/*                                                                        */
183
/*    _uxe_host_stack_configuration_interface_get         PORTABLE C      */
184
/*                                                           6.3.0        */
185
/*  AUTHOR                                                                */
186
/*                                                                        */
187
/*    Chaoqiong Xiao, Microsoft Corporation                               */
188
/*                                                                        */
189
/*  DESCRIPTION                                                           */
190
/*                                                                        */
191
/*    This function checks errors in host stack interface get function    */
192
/*    call.                                                               */
193
/*                                                                        */
194
/*  INPUT                                                                 */
195
/*                                                                        */
196
/*    configuration                         Pointer to configuration      */
197
/*    interface_index                       Index of interface            */
198
/*    alternate_setting_index               Index of alternate setting    */
199
/*    interface                             Destination of interface      */
200
/*                                                                        */
201
/*  OUTPUT                                                                */
202
/*                                                                        */
203
/*    None                                                                */
204
/*                                                                        */
205
/*  CALLS                                                                 */
206
/*                                                                        */
207
/*    _ux_host_stack_configuration_interface_get                          */
208
/*                                          Host stack interface get      */
209
/*                                                                        */
210
/*  CALLED BY                                                             */
211
/*                                                                        */
212
/*    Application                                                         */
213
/*                                                                        */
214
/**************************************************************************/
215
UINT  _uxe_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration,
216
                                                UINT interface_index, UINT alternate_setting_index,
217
                                                UX_INTERFACE **ux_interface)
218
{
219
220
    /* Sanity checks.  */
221
    if ((configuration == UX_NULL) || (ux_interface == UX_NULL))
222
        return(UX_INVALID_PARAMETER);
223
224
    /* Invoke interface get function.  */
225
    return(_ux_host_stack_configuration_interface_get(configuration,
226
                    interface_index, alternate_setting_index, ux_interface));
227
}