GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_configuration_descriptor_parse.c Lines: 18 18 100.0 %
Date: 2026-03-06 18:57:10 Branches: 6 6 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_descriptor_parse       PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function reads the entire configuration descriptor and         */
45
/*    enumerates the interfaces, binds the interface to a class driver... */
46
/*    if the device has multiple configurations, we read all the          */
47
/*    configurations but do not instantiate any configuration. Rather we  */
48
/*    let a class driver do the work.                                     */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    device                                Pointer to device             */
53
/*    configuration                         Pointer to configuration      */
54
/*    configuration_index                   Index of configuration        */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    Completion Status                                                   */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _ux_host_stack_interfaces_scan        Scan host interfaces          */
63
/*    _ux_host_stack_transfer_request       Process transfer request      */
64
/*    _ux_utility_memory_allocate           Allocate block of memory      */
65
/*    _ux_utility_memory_free               Free block of memory          */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    USBX Components                                                     */
70
/*                                                                        */
71
/**************************************************************************/
72
1060
UINT  _ux_host_stack_configuration_descriptor_parse(UX_DEVICE *device, UX_CONFIGURATION *configuration,
73
                                                                        UINT configuration_index)
74
{
75
76
UX_TRANSFER     *transfer_request;
77
UINT            status;
78
UCHAR           *descriptor;
79
UX_ENDPOINT     *control_endpoint;
80
ULONG           total_configuration_length;
81
82
83
    /* Retrieve the pointer to the control endpoint and its transfer_request.  */
84
1060
    control_endpoint =  &device -> ux_device_control_endpoint;
85
1060
    transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
86
87
    /* Retrieve the size of all the configuration descriptor.  */
88
1060
    total_configuration_length =  configuration -> ux_configuration_descriptor.wTotalLength;
89
90
    /* Allocate enough memory to read all descriptors attached to this configuration.  */
91
1060
    descriptor =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, total_configuration_length);
92
93
    /* Determine if the memory was allocated.  */
94
1060
    if (descriptor == UX_NULL)
95
    {
96
97
        /* No, return an error.  */
98
2
        return(UX_MEMORY_INSUFFICIENT);
99
    }
100
    else
101
    {
102
103
        /* Create a transfer_request for the GET_DESCRIPTOR request.  */
104
1058
        transfer_request -> ux_transfer_request_data_pointer =      descriptor;
105
1058
        transfer_request -> ux_transfer_request_requested_length =  total_configuration_length;
106
1058
        transfer_request -> ux_transfer_request_function =          UX_GET_DESCRIPTOR;
107
1058
        transfer_request -> ux_transfer_request_type =              UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE;
108
1058
        transfer_request -> ux_transfer_request_value =             configuration_index | (UINT)(UX_CONFIGURATION_DESCRIPTOR_ITEM << 8);
109
1058
        transfer_request -> ux_transfer_request_index =             0;
110
111
        /* Send request to HCD layer.  */
112
1058
        status =  _ux_host_stack_transfer_request(transfer_request);
113
114
        /* Check for correct transfer and entire descriptor returned.  */
115

1058
        if((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == total_configuration_length))
116
        {
117
118
            /* The entire descriptor now contains the configuration descriptor,
119
               the interface(s) descriptors, all alternate settings, endpoints
120
               and descriptor specific to the class. The descriptor is parsed for all interfaces.  */
121
1055
            status =  _ux_host_stack_interfaces_scan(configuration, descriptor);
122
        }
123
    }
124
125
    /* Free all used resources.  */
126
1058
    _ux_utility_memory_free(descriptor);
127
128
    /* Return completion status.  */
129
1058
    return(status);
130
}
131