GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_report_item_analyse.c Lines: 22 24 91.7 %
Date: 2026-03-06 18:57:10 Branches: 6 8 75.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
/**   HID Class                                                           */
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_class_hid.h"
30
#include "ux_host_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_host_class_hid_report_item_analyse              PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function gets the report descriptor and analyzes it.           */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    descriptor                            Pointer to descriptor         */
50
/*    length                                Length of descriptor          */
51
/*    item                                  Pointer to item               */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    None                                                                */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    HID Class                                                           */
64
/*                                                                        */
65
/**************************************************************************/
66
14080
UINT  _ux_host_class_hid_report_item_analyse(UCHAR *descriptor, ULONG length, UX_HOST_CLASS_HID_ITEM *item)
67
{
68
69
UCHAR       item_byte;
70
14080
UINT        result = UX_SUCCESS;
71
72
    /* Make sure descriptor has minimal length.*/
73
14080
    if (length == 0)
74
    {
75
        return(UX_DESCRIPTOR_CORRUPTED);
76
    }
77
78
    /* Get the first byte from the descriptor.  */
79
14080
    item_byte =  *descriptor;
80
81
    /*  We need to determine if this is a short or long item.
82
        For long items, the tag is always 1111.  */
83
14080
    if ((item_byte & UX_HOST_CLASS_HID_ITEM_TAG_MASK) == UX_HOST_CLASS_HID_ITEM_TAG_LONG)
84
    {
85
86
        /* We have a long item, mark its format.  */
87
6
        item -> ux_host_class_hid_item_report_format =  UX_HOST_CLASS_HID_ITEM_TAG_LONG;
88
89
        /* Set the type.  */
90
6
        item -> ux_host_class_hid_item_report_type =  (item_byte >> 2) & 3;
91
92
        /* Make sure descriptor has minimal length.*/
93
6
        if (length >= 3)
94
        {
95
            /* Get its length (byte 1).  */
96
6
            item -> ux_host_class_hid_item_report_length =  (USHORT) *(descriptor + 1);
97
98
            /* Then the tag (byte 2).  */
99
6
            item -> ux_host_class_hid_item_report_tag =  *(descriptor + 2);
100
        }
101
        else
102
        {
103
            result = UX_DESCRIPTOR_CORRUPTED;
104
        }
105
    }
106
    else
107
    {
108
109
        /* We have a short item. Mark its format */
110
14074
        item -> ux_host_class_hid_item_report_format =  UX_HOST_CLASS_HID_ITEM_TAG_SHORT;
111
112
        /* Get the length of the item.  */
113
14074
        switch (item_byte & UX_HOST_CLASS_HID_ITEM_LENGTH_MASK)
114
        {
115
116
31
        case 3:
117
118
31
            item -> ux_host_class_hid_item_report_length =  4;
119
31
            break;
120
121
14043
        default:
122
123
14043
            item -> ux_host_class_hid_item_report_length =  item_byte & UX_HOST_CLASS_HID_ITEM_LENGTH_MASK;
124
14043
            break;
125
        }
126
127
        /* Set the type.  */
128
14074
        item -> ux_host_class_hid_item_report_type =  (item_byte >> 2) & 3;
129
130
        /* Then the tag.  */
131
14074
        item -> ux_host_class_hid_item_report_tag =  (item_byte >> 4) & 0xf;
132
133
        /* Mark its format. For short items, this is always 1. */
134
14074
        item -> ux_host_class_hid_item_report_format = 1;
135
136
    }
137
138
    /* Return result.  */
139
14080
    return(result);
140
}