GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_configuration_interface_scan.c Lines: 33 33 100.0 %
Date: 2026-03-06 18:57:10 Branches: 16 16 100.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_scan         PORTABLE C      */
37
/*                                                           6.1.12       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function will scan all default interfaces for a specific       */
45
/*    configuration and call the registered class with the                */
46
/*    Class/SubClass/Protocol of the interface.                           */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    configuration                         Configuration pointer         */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Result of operation                                                 */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_stack_class_call             Call class command            */
59
/*    _ux_host_stack_device_configuration_select                          */
60
/*                                          Select configuration          */
61
/*    _ux_host_stack_class_call             Call class from host stack    */
62
/*    (ux_host_class_entry_function)        Class entry function          */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    USBX Components                                                     */
67
/*                                                                        */
68
/**************************************************************************/
69
842
UINT  _ux_host_stack_configuration_interface_scan(UX_CONFIGURATION *configuration)
70
{
71
72
UX_INTERFACE            *interface_ptr;
73
UINT                    nb_class_owners;
74
UX_HOST_CLASS           *class_ptr;
75
UX_HOST_CLASS_COMMAND   class_command;
76
UINT                    status;
77
78
79
    /* Initialize class owners to 0.  */
80
842
    nb_class_owners =  0;
81
82
    /* Get the first interface container for this configuration.  */
83
842
    interface_ptr =  configuration -> ux_configuration_first_interface;
84
85
    /* We now scan all the alternate settings 0 for each of the interfaces.  */
86
2555
    while (interface_ptr !=  UX_NULL)
87
    {
88
89
        /* Is there a default interface?  */
90
1713
        if(interface_ptr -> ux_interface_descriptor.bAlternateSetting == 0)
91
        {
92
93
            /* We have a default interface for this configuration. Call each class
94
               with the class\subclass\protocol.  We include the IAD for the cdc classes.  */
95
1477
            class_command.ux_host_class_command_request      =   UX_HOST_CLASS_COMMAND_QUERY;
96
1477
            class_command.ux_host_class_command_container    =   (VOID *)interface_ptr;
97
1477
            class_command.ux_host_class_command_usage        =   UX_HOST_CLASS_COMMAND_USAGE_CSP;
98
1477
            class_command.ux_host_class_command_class        =   interface_ptr -> ux_interface_descriptor.bInterfaceClass;
99
1477
            class_command.ux_host_class_command_subclass     =   interface_ptr -> ux_interface_descriptor.bInterfaceSubClass;
100
1477
            class_command.ux_host_class_command_protocol     =   interface_ptr -> ux_interface_descriptor.bInterfaceProtocol;
101
1477
            class_command.ux_host_class_command_iad_class    =   interface_ptr -> ux_interface_iad_class   ;
102
1477
            class_command.ux_host_class_command_iad_subclass =   interface_ptr -> ux_interface_iad_subclass;
103
1477
            class_command.ux_host_class_command_iad_protocol =   interface_ptr -> ux_interface_iad_protocol;
104
105
1477
            class_ptr =  _ux_host_stack_class_call(&class_command);
106
107
            /* On return, either we have found a class or the interface is still an orphan.  */
108
1477
            if (class_ptr != UX_NULL)
109
            {
110
111
                /* There is a class.  */
112
1416
                nb_class_owners++;
113
1416
                interface_ptr -> ux_interface_class =  class_ptr;
114
            }
115
        }
116
117
        /* point to the next interface until end of the list.  */
118
1713
        interface_ptr =  interface_ptr -> ux_interface_next_interface;
119
    }
120
121
#if defined(UX_HOST_STANDALONE)
122
123
    /* Activated later in state machine.  */
124
    status = (nb_class_owners > 0) ? UX_SUCCESS : UX_NO_CLASS_MATCH;
125
    return(status);
126
#else
127
128
    /* Assume no classes.  */
129
842
    status = UX_NO_CLASS_MATCH;
130
131
    /* Check the number of class owner found.  */
132
842
    if (nb_class_owners != 0)
133
    {
134
135
        /* If we have found one or more classes for any of the interfaces,
136
           we can safely do a SET_CONFIGURATION of the device.  */
137
828
        status =  _ux_host_stack_device_configuration_select(configuration);
138
139
        /* Check the completion status.  */
140
828
        if (status == UX_SUCCESS)
141
        {
142
143
            /* The device is in the CONFIGURED state, we have to call each of the classes
144
               again with an ACTIVATE signal.  */
145
809
            interface_ptr =  configuration -> ux_configuration_first_interface;
146
147
2471
            while (interface_ptr != UX_NULL)
148
            {
149
150
                /* Is there a default interface?  */
151
1663
                if (interface_ptr -> ux_interface_descriptor.bAlternateSetting == 0)
152
                {
153
154
                    /* We have found the default interface. If this interface is owned,
155
                       activate its class.  */
156
1428
                    class_command.ux_host_class_command_request =    UX_HOST_CLASS_COMMAND_ACTIVATE;
157
1428
                    class_command.ux_host_class_command_container =  (VOID *) interface_ptr;
158
159
1428
                    if (interface_ptr -> ux_interface_class != UX_NULL)
160
                    {
161
162
                        /* Save the class in the command container */
163
1385
                        class_command.ux_host_class_command_class_ptr =  interface_ptr -> ux_interface_class;
164
165
                        /* Send the ACTIVATE command to the class */
166
1385
                        status =  interface_ptr -> ux_interface_class -> ux_host_class_entry_function(&class_command);
167
168
                    }
169
                }
170
171
                /* Point to the next interface until end of the list.  */
172
1662
                interface_ptr =  interface_ptr -> ux_interface_next_interface;
173
            }
174
        }
175
    }
176
177
    /* Return operation result.  */
178
841
    return(status);
179
#endif
180
}
181