GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_class_device_scan.c Lines: 24 24 100.0 %
Date: 2026-03-06 18:57:10 Branches: 4 4 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
#if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DISABLE)
33
#if defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_VIDPID_DISABLE) && \
34
    defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DCSP_DISABLE)
35
#error When device driver scan is enabled at least one of scan method must be enabled in (VIDPID, DeviceClassSubclassProtocol)
36
#endif
37
#endif
38
39
/**************************************************************************/
40
/*                                                                        */
41
/*  FUNCTION                                               RELEASE        */
42
/*                                                                        */
43
/*    _ux_host_stack_class_device_scan                    PORTABLE C      */
44
/*                                                           6.1.10       */
45
/*  AUTHOR                                                                */
46
/*                                                                        */
47
/*    Chaoqiong Xiao, Microsoft Corporation                               */
48
/*                                                                        */
49
/*  DESCRIPTION                                                           */
50
/*                                                                        */
51
/*    This function will scan all registered classes with a device        */
52
/*    candidate. Priority is given to the PID/VID and then the            */
53
/*    Class/Subclass/Protocol.                                            */
54
/*                                                                        */
55
/*  INPUT                                                                 */
56
/*                                                                        */
57
/*    device                                Pointer to device             */
58
/*                                                                        */
59
/*  OUTPUT                                                                */
60
/*                                                                        */
61
/*    Completion Status                                                   */
62
/*                                                                        */
63
/*  CALLS                                                                 */
64
/*                                                                        */
65
/*    _ux_host_stack_class_call             Call host stack class         */
66
/*    (ux_host_class_entry_function)        Class entry function          */
67
/*                                                                        */
68
/*  CALLED BY                                                             */
69
/*                                                                        */
70
/*    USBX Components                                                     */
71
/*                                                                        */
72
/**************************************************************************/
73
927
UINT  _ux_host_stack_class_device_scan(UX_DEVICE *device)
74
{
75
#if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DISABLE)
76
77
UINT                        status;
78
927
UX_HOST_CLASS               *class_inst = UX_NULL;
79
UX_HOST_CLASS_COMMAND       class_command;
80
81
    /* Perform the command initialization.  */
82
927
    class_command.ux_host_class_command_request      =   UX_HOST_CLASS_COMMAND_QUERY;
83
927
    class_command.ux_host_class_command_container    =   (VOID *) device;
84
927
    class_command.ux_host_class_command_vid          =   device -> ux_device_descriptor.idVendor;
85
927
    class_command.ux_host_class_command_pid          =   device -> ux_device_descriptor.idProduct;
86
927
    class_command.ux_host_class_command_class        =   device -> ux_device_descriptor.bDeviceClass;
87
927
    class_command.ux_host_class_command_subclass     =   device -> ux_device_descriptor.bDeviceSubClass;
88
927
    class_command.ux_host_class_command_protocol     =   device -> ux_device_descriptor.bDeviceProtocol;
89
927
    class_command.ux_host_class_command_iad_class    =   0;
90
927
    class_command.ux_host_class_command_iad_subclass =   0;
91
927
    class_command.ux_host_class_command_iad_protocol =   0;
92
93
#if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_VIDPID_DISABLE)
94
    /* We start with the PID/VID for this device.  */
95
927
    class_command.ux_host_class_command_usage =  UX_HOST_CLASS_COMMAND_USAGE_PIDVID;
96
927
    class_inst =  _ux_host_stack_class_call(&class_command);
97
#endif
98
99
#if !defined(UX_HOST_STACK_DEVICE_DRIVER_SCAN_DCSP_DISABLE)
100
    /* On return, either we have found a class or the device is still an orphan.  */
101
927
    if (class_inst == UX_NULL)
102
    {
103
104
        /* It the PID/VID did not work, we continue looking for the Class\Subclass\Protocol match. */
105
912
        class_command.ux_host_class_command_usage        =   UX_HOST_CLASS_COMMAND_USAGE_DCSP;
106
912
        class_inst =  _ux_host_stack_class_call(&class_command);
107
108
    }
109
#endif
110
111
    /* On return, either we have found a class or the device is still an orphan.  */
112
927
    if (class_inst != UX_NULL)
113
    {
114
115
87
        device -> ux_device_class =  class_inst;
116
117
#if defined(UX_HOST_STANDALONE)
118
119
        /* Activation may take time, run as state machine.  */
120
        status = UX_SUCCESS;
121
        return(status);
122
#else
123
87
        class_command.ux_host_class_command_class_ptr =  class_inst;
124
87
        class_command.ux_host_class_command_request =  UX_HOST_CLASS_COMMAND_ACTIVATE;
125
87
        status =  device -> ux_device_class ->  ux_host_class_entry_function(&class_command);
126
127
        /* Return result of activation.  */
128
87
        return(status);
129
#endif
130
    }
131
132
#endif
133
134
    /* Return an error.  */
135
840
    return(UX_NO_CLASS_MATCH);
136
}
137