GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_device_string_get.c Lines: 17 21 81.0 %
Date: 2026-03-06 18:57:10 Branches: 4 10 40.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_device_string_get                    PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function obtains the device string descriptor.                 */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    device                                Pointer to device instance    */
49
/*    descriptor_buffer                     Pointer to a buffer to fill   */
50
/*                                          LANGID or STRING descriptor   */
51
/*    length                                Length of buffer              */
52
/*    language_id                           0 to obtain LANGID descriptor */
53
/*                                          valid language ID to obtain   */
54
/*                                          string descriptor             */
55
/*    string_index                          Index of the string           */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    Completion Status                                                   */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    _ux_host_stack_transfer_request       Process transfer request      */
64
/*    _ux_utility_semaphore_get             Get Semaphore                 */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application                                                         */
69
/*                                                                        */
70
/**************************************************************************/
71
4
UINT  _ux_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index)
72
{
73
#if defined(UX_HOST_STANDALONE)
74
UX_INTERRUPT_SAVE_AREA
75
#endif
76
UX_ENDPOINT     *control_endpoint;
77
UX_TRANSFER     *transfer_request;
78
UINT            status;
79
80
81
    /* Do a sanity check on the device handle.  */
82
4
    if (device -> ux_device_handle != (ULONG) (ALIGN_TYPE) device)
83
    {
84
85
        /* Error trap. */
86
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DEVICE_HANDLE_UNKNOWN);
87
88
        /* If trace is enabled, insert this event into the trace buffer.  */
89
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0)
90
91
1
        return(UX_DEVICE_HANDLE_UNKNOWN);
92
    }
93
94
    /* If trace is enabled, insert this event into the trace buffer.  */
95
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_STRING_GET, device, descriptor_buffer, length, (language_id << 16) | string_index, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
96
97
    /* We need to get the default control endpoint transfer request pointer.  */
98
3
    control_endpoint =  &device -> ux_device_control_endpoint;
99
3
    transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
100
101
#if defined(UX_HOST_STANDALONE)
102
    UX_DISABLE
103
    if ((device -> ux_device_flags & UX_DEVICE_FLAG_LOCK) ||
104
        (transfer_request -> ux_transfer_request_flags & UX_TRANSFER_FLAG_LOCK))
105
    {
106
        UX_RESTORE
107
        return(UX_BUSY);
108
    }
109
    device -> ux_device_flags |= UX_DEVICE_FLAG_LOCK;
110
    transfer_request -> ux_transfer_request_flags |=
111
                (UX_TRANSFER_FLAG_LOCK | UX_TRANSFER_FLAG_AUTO_DEVICE_UNLOCK);
112
    UX_RESTORE
113
#else
114
115
    /* Protect the control endpoint semaphore here.  It will be unprotected in the
116
       transfer request function.  */
117
3
    status =  _ux_host_semaphore_get(&device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
118
119
    /* Check for status.  */
120
3
    if (status != UX_SUCCESS)
121
1
        return(UX_SEMAPHORE_ERROR);
122
#endif
123
124
    /* Create a transfer request for the GET_DEVICE_ID request.  */
125
2
    transfer_request -> ux_transfer_request_data_pointer =      descriptor_buffer;
126
2
    transfer_request -> ux_transfer_request_requested_length =  length;
127
2
    transfer_request -> ux_transfer_request_function =          UX_GET_DESCRIPTOR;
128
2
    transfer_request -> ux_transfer_request_type =              UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE;
129
2
    transfer_request -> ux_transfer_request_value =             (UX_STRING_DESCRIPTOR_ITEM << 8) | string_index;
130
2
    transfer_request -> ux_transfer_request_index =             (language_id);
131
132
    /* Send request to HCD layer.  */
133
2
    status =  _ux_host_stack_transfer_request(transfer_request);
134
135
    /* Return completion status.  */
136
2
    return(status);
137
}
138
139
140
/**************************************************************************/
141
/*                                                                        */
142
/*  FUNCTION                                               RELEASE        */
143
/*                                                                        */
144
/*    _uxe_host_stack_device_string_get                   PORTABLE C      */
145
/*                                                           6.3.0        */
146
/*  AUTHOR                                                                */
147
/*                                                                        */
148
/*    Chaoqiong Xiao, Microsoft Corporation                               */
149
/*                                                                        */
150
/*  DESCRIPTION                                                           */
151
/*                                                                        */
152
/*    This function checks errors in host stack device get function call. */
153
/*                                                                        */
154
/*  INPUT                                                                 */
155
/*                                                                        */
156
/*    device                                Pointer to device instance    */
157
/*    descriptor_buffer                     Pointer to a buffer to fill   */
158
/*                                          LANGID or STRING descriptor   */
159
/*    length                                Length of buffer              */
160
/*    language_id                           0 to obtain LANGID descriptor */
161
/*                                          valid language ID to obtain   */
162
/*                                          string descriptor             */
163
/*    string_index                          Index of the string           */
164
/*                                                                        */
165
/*  OUTPUT                                                                */
166
/*                                                                        */
167
/*    None                                                                */
168
/*                                                                        */
169
/*  CALLS                                                                 */
170
/*                                                                        */
171
/*    _ux_host_stack_device_string_get      String descriptor get         */
172
/*                                                                        */
173
/*  CALLED BY                                                             */
174
/*                                                                        */
175
/*    Application                                                         */
176
/*                                                                        */
177
/**************************************************************************/
178
UINT  _uxe_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index)
179
{
180
181
    /* Sanity check.  */
182
    if ((device == UX_NULL) || (descriptor_buffer == UX_NULL) || (length == 0))
183
        return(UX_INVALID_PARAMETER);
184
185
    /* Invoke string descriptor get function.  */
186
    return(_ux_host_stack_device_string_get(device, descriptor_buffer, length, language_id, string_index));
187
}