GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_global_item_parse.c Lines: 67 67 100.0 %
Date: 2024-12-12 17:16:36 Branches: 21 21 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   HID Class                                                           */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
23
/* Include necessary system files.  */
24
25
#define UX_SOURCE_CODE
26
27
#include "ux_api.h"
28
#include "ux_host_class_hid.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_class_hid_global_item_parse                PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function parses a global item from the report descriptor.      */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    hid                                   Pointer to HID class          */
49
/*    item                                  Pointer to item               */
50
/*    descriptor                            Pointer to descriptor         */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_class_hid_item_data_get      Get data item                 */
59
/*    _ux_utility_memory_copy               Copy memory block             */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    HID Class                                                           */
64
/*                                                                        */
65
/*  RELEASE HISTORY                                                       */
66
/*                                                                        */
67
/*    DATE              NAME                      DESCRIPTION             */
68
/*                                                                        */
69
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71
/*                                            verified memset and memcpy  */
72
/*                                            cases,                      */
73
/*                                            resulting in version 6.1    */
74
/*                                                                        */
75
/**************************************************************************/
76
7382
UINT  _ux_host_class_hid_global_item_parse(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_ITEM *item, UCHAR *descriptor)
77
{
78
79
UX_HOST_CLASS_HID_PARSER     *hid_parser;
80
81
82
    /* Get the temporary parser structure pointer.  */
83
7382
    hid_parser =  &hid -> ux_host_class_hid_parser;
84
85
    /* Get the tag of the item structure and process it.  */
86



7382
    switch(item -> ux_host_class_hid_item_report_tag)
87
    {
88
89
1443
    case UX_HOST_CLASS_HID_GLOBAL_TAG_USAGE_PAGE:
90
91
        /* Usage Page Tag.  */
92
1443
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_usage_page =
93
1443
                                                _ux_host_class_hid_item_data_get(descriptor, item);
94
1443
        break;
95
96
97
786
    case UX_HOST_CLASS_HID_GLOBAL_TAG_LOGICAL_MINIMUM:
98
99
        /* Logical Minimum Tag.  */
100
786
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_logical_min =
101
786
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
102
786
        break;
103
104
105
801
    case UX_HOST_CLASS_HID_GLOBAL_TAG_LOGICAL_MAXIMUM:
106
107
        /* Logical Maximum Tag.  */
108
801
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_logical_max =
109
801
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
110
801
        break;
111
112
113
18
    case UX_HOST_CLASS_HID_GLOBAL_TAG_PHYSICAL_MINIMUM:
114
115
        /* Physical Minimum Tag.  */
116
18
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_physical_min =
117
18
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
118
18
        break;
119
120
121
18
    case UX_HOST_CLASS_HID_GLOBAL_TAG_PHYSICAL_MAXIMUM:
122
123
        /* Physical Maximum Tag.  */
124
18
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_physical_max =
125
18
                                                (SLONG) _ux_host_class_hid_item_data_get(descriptor, item);
126
18
        break;
127
128
129
14
    case UX_HOST_CLASS_HID_GLOBAL_TAG_UNIT_EXPONENT:
130
131
        /* Unit Exponent Tag.  */
132
14
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_unit_expo =
133
14
                                                _ux_host_class_hid_item_data_get(descriptor, item);
134
14
        break;
135
136
137
19
    case UX_HOST_CLASS_HID_GLOBAL_TAG_UNIT:
138
139
        /* Unit tag.  */
140
19
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_unit =
141
19
                                                _ux_host_class_hid_item_data_get(descriptor, item);
142
19
        break;
143
144
145
2004
    case UX_HOST_CLASS_HID_GLOBAL_TAG_REPORT_SIZE:
146
147
        /* Report Size tag.  */
148
2004
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_size =
149
2004
                                                _ux_host_class_hid_item_data_get(descriptor, item);
150
151
2004
        if (hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_size > UX_HOST_CLASS_HID_REPORT_SIZE)
152
        {
153
154
            /* Error trap. */
155
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_REPORT_OVERFLOW);
156
157
            /* If trace is enabled, insert this event into the trace buffer.  */
158
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_REPORT_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
159
160
3
            return(UX_HOST_CLASS_HID_REPORT_OVERFLOW);
161
        }
162
163
2001
        break;
164
165
166
243
    case UX_HOST_CLASS_HID_GLOBAL_TAG_REPORT_ID:
167
168
        /* Report ID tag.  */
169
243
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_id =
170
243
                                                _ux_host_class_hid_item_data_get(descriptor, item);
171
243
        break;
172
173
174
2003
    case UX_HOST_CLASS_HID_GLOBAL_TAG_REPORT_COUNT:
175
176
        /* Report Count tag.  */
177
2003
        hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_count =
178
2003
                                                _ux_host_class_hid_item_data_get(descriptor, item);
179
180
2003
        if (hid_parser -> ux_host_class_hid_parser_global.ux_host_class_hid_global_item_report_count > UX_HOST_CLASS_HID_USAGES)
181
        {
182
183
            /* Error trap. */
184
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_USAGE_OVERFLOW);
185
186
            /* If trace is enabled, insert this event into the trace buffer.  */
187
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_USAGE_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
188
189
3
            return(UX_HOST_CLASS_HID_USAGE_OVERFLOW);
190
        }
191
192
2000
        break;
193
194
21
    case UX_HOST_CLASS_HID_GLOBAL_TAG_PUSH:
195
196
        /* Push tag.  */
197
21
        if (hid_parser -> ux_host_class_hid_parser_number_global >= UX_HOST_CLASS_HID_MAX_GLOBAL)
198
        {
199
200
            /* Error trap. */
201
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_PUSH_OVERFLOW);
202
203
            /* If trace is enabled, insert this event into the trace buffer.  */
204
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_PUSH_OVERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
205
206
3
            return(UX_HOST_CLASS_HID_PUSH_OVERFLOW);
207
        }
208
209
        else
210
18
            _ux_utility_memory_copy(&hid_parser -> ux_host_class_hid_parser_global_pool[hid_parser -> ux_host_class_hid_parser_number_global++],
211
18
                                        &hid_parser -> ux_host_class_hid_parser_global, sizeof(UX_HOST_CLASS_HID_GLOBAL_ITEM)); /* Use case of memcpy is verified. */
212
18
        break;
213
214
215
9
    case UX_HOST_CLASS_HID_GLOBAL_TAG_POP:
216
217
        /* Pop tag.  */
218
9
        if(hid_parser -> ux_host_class_hid_parser_number_global == 0)
219
        {
220
221
            /* Error trap. */
222
3
            _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_POP_UNDERFLOW);
223
224
            /* If trace is enabled, insert this event into the trace buffer.  */
225
            UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_POP_UNDERFLOW, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
226
227
3
            return(UX_HOST_CLASS_HID_POP_UNDERFLOW);
228
        }
229
        else
230
6
            _ux_utility_memory_copy(&hid_parser -> ux_host_class_hid_parser_global,
231
6
                                   &hid_parser -> ux_host_class_hid_parser_global_pool[--hid_parser -> ux_host_class_hid_parser_number_global],
232
                                        sizeof(UX_HOST_CLASS_HID_GLOBAL_ITEM)); /* Use case of memcpy is verified. */
233
234
6
        break;
235
236
237
3
    default:
238
239
        /* Error trap. */
240
3
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_TAG_UNSUPPORTED);
241
242
        /* If trace is enabled, insert this event into the trace buffer.  */
243
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_HID_TAG_UNSUPPORTED, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
244
245
        /* This tag was not recognized or is not supported.  */
246
3
        return(UX_HOST_CLASS_HID_TAG_UNSUPPORTED);
247
    }
248
249
    /* We get here when the tag has been processed successfully.  */
250
7367
    return(UX_SUCCESS);
251
}
252