GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_keyboard_ioctl.c Lines: 17 21 81.0 %
Date: 2024-12-12 17:16:36 Branches: 6 8 75.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 Keyboard Client                                                 */
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_class_hid_keyboard.h"
30
#include "ux_host_stack.h"
31
32
extern UX_HOST_CLASS_HID_KEYBOARD_LAYOUT ux_host_class_hid_keyboard_layout;
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _ux_host_class_hid_keyboard_ioctl                   PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Chaoqiong Xiao, Microsoft Corporation                               */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function is the ioctl entry point for the application to       */
47
/*    configure the HID keyboard device.                                  */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    keyboard_instance                    Pointer to hid keyboard        */
52
/*    ioctl_function                       ioctl function                 */
53
/*    parameter                            pointer to parameter/structure */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    Completion Status                                                   */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*                                                                        */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    HID Keyboard Client                                                 */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73
/*                                            resulting in version 6.1    */
74
/*                                                                        */
75
/**************************************************************************/
76
6
UINT _ux_host_class_hid_keyboard_ioctl(UX_HOST_CLASS_HID_KEYBOARD *keyboard_instance,
77
                                        ULONG ioctl_function, VOID *parameter)
78
{
79
80
6
UINT status = UX_SUCCESS;
81
82
83

6
    switch(ioctl_function)
84
    {
85
86
2
    case UX_HID_KEYBOARD_IOCTL_SET_LAYOUT:
87
88
        /* Change the keyboard layout setting.  */
89
2
        keyboard_instance -> ux_host_class_hid_keyboard_layout = (parameter == UX_NULL) ?
90
2
                                                                    &ux_host_class_hid_keyboard_layout :
91
                                                                    (UX_HOST_CLASS_HID_KEYBOARD_LAYOUT *) parameter;
92
93
2
        break;
94
95
2
    case UX_HID_KEYBOARD_IOCTL_DISABLE_KEYS_DECODE:
96
97
        /* Disable the keys decode setting.  */
98
2
        keyboard_instance -> ux_host_class_hid_keyboard_keys_decode_disable = UX_TRUE;
99
100
2
        break;
101
102
1
    case UX_HID_KEYBOARD_IOCTL_ENABLE_KEYS_DECODE:
103
104
        /* Enable the keys decode setting.  */
105
1
        keyboard_instance -> ux_host_class_hid_keyboard_keys_decode_disable = UX_FALSE;
106
107
1
        break;
108
109
1
    default:
110
111
        /* Error trap. */
112
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
113
114
        /* If trace is enabled, insert this event into the trace buffer.  */
115
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
116
117
        /* Function not supported. Return an error.  */
118
1
        status =  UX_FUNCTION_NOT_SUPPORTED;
119
120
    }
121
122
    /* Return status to caller.  */
123
6
    return(status);
124
}
125
126
/**************************************************************************/
127
/*                                                                        */
128
/*  FUNCTION                                               RELEASE        */
129
/*                                                                        */
130
/*    _uxe_host_class_hid_keyboard_ioctl                  PORTABLE C      */
131
/*                                                           6.3.0        */
132
/*  AUTHOR                                                                */
133
/*                                                                        */
134
/*    Chaoqiong Xiao, Microsoft Corporation                               */
135
/*                                                                        */
136
/*  DESCRIPTION                                                           */
137
/*                                                                        */
138
/*    This function checks errors in HID keyboard ioctl function call.    */
139
/*                                                                        */
140
/*  INPUT                                                                 */
141
/*                                                                        */
142
/*    keyboard_instance                    Pointer to hid keyboard        */
143
/*    ioctl_function                       IOCTL function                 */
144
/*    parameter                            Pointer to parameter/structure */
145
/*                                                                        */
146
/*  OUTPUT                                                                */
147
/*                                                                        */
148
/*    Status                                                              */
149
/*                                                                        */
150
/*  CALLS                                                                 */
151
/*                                                                        */
152
/*    _ux_host_class_hid_keyboard_ioctl    IOCTL function                 */
153
/*                                                                        */
154
/*  CALLED BY                                                             */
155
/*                                                                        */
156
/*    Application                                                         */
157
/*                                                                        */
158
/*  RELEASE HISTORY                                                       */
159
/*                                                                        */
160
/*    DATE              NAME                      DESCRIPTION             */
161
/*                                                                        */
162
/*  10-31-2023     Chaoqiong Xiao           Initial Version 6.3.0         */
163
/*                                                                        */
164
/**************************************************************************/
165
UINT _uxe_host_class_hid_keyboard_ioctl(UX_HOST_CLASS_HID_KEYBOARD *keyboard_instance,
166
                                        ULONG ioctl_function, VOID *parameter)
167
{
168
169
    /* Sanity checks.  */
170
    if (keyboard_instance == UX_NULL)
171
        return(UX_INVALID_PARAMETER);
172
173
    /* Invoke report ID get function.  */
174
    return(_ux_host_class_hid_keyboard_ioctl(keyboard_instance, ioctl_function, parameter));
175
}