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 |
|
|
/** Device HID Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
#define UX_SOURCE_CODE |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* Include necessary system files. */ |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_device_class_hid.h" |
30 |
|
|
#include "ux_device_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_device_class_hid_report_set PORTABLE C */ |
38 |
|
|
/* 6.3.0 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function gets from the control pipe a report to be set from */ |
46 |
|
|
/* the host. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* hid Pointer to hid instance */ |
51 |
|
|
/* descriptor_type Descriptor type */ |
52 |
|
|
/* descriptor_index Index of descriptor */ |
53 |
|
|
/* host_length Length requested by host */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* Completion Status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* _ux_utility_memory_copy Memory copy */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* Device HID */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
164 |
UINT _ux_device_class_hid_report_set(UX_SLAVE_CLASS_HID *hid, ULONG descriptor_type, |
69 |
|
|
ULONG request_index, ULONG host_length) |
70 |
|
|
{ |
71 |
|
|
|
72 |
|
|
UX_SLAVE_DEVICE *device; |
73 |
|
|
UX_SLAVE_TRANSFER *transfer_request; |
74 |
|
|
UX_SLAVE_ENDPOINT *endpoint; |
75 |
|
|
UX_SLAVE_CLASS_HID_EVENT hid_event; |
76 |
|
|
UCHAR *hid_buffer; |
77 |
|
|
|
78 |
|
|
UX_PARAMETER_NOT_USED(request_index); |
79 |
|
|
UX_PARAMETER_NOT_USED(host_length); |
80 |
|
|
|
81 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
82 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_HID_REPORT_SET, hid, descriptor_type, request_index, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0) |
83 |
|
|
|
84 |
|
|
/* Get the pointer to the device. */ |
85 |
|
164 |
device = &_ux_system_slave -> ux_system_slave_device; |
86 |
|
|
|
87 |
|
|
/* Get the control endpoint associated with the device. */ |
88 |
|
164 |
endpoint = &device -> ux_slave_device_control_endpoint; |
89 |
|
|
|
90 |
|
|
/* Get the pointer to the transfer request associated with the endpoint. */ |
91 |
|
164 |
transfer_request = &endpoint -> ux_slave_endpoint_transfer_request; |
92 |
|
|
|
93 |
|
|
/* Set the event type to OUTPUT. */ |
94 |
|
164 |
hid_event.ux_device_class_hid_event_report_type = descriptor_type; |
95 |
|
|
|
96 |
|
|
/* Get HID data address. */ |
97 |
|
164 |
hid_buffer = transfer_request -> ux_slave_transfer_request_data_pointer; |
98 |
|
|
|
99 |
|
|
/* Check for report ID in this HID descriptor. */ |
100 |
✓✓ |
164 |
if (hid -> ux_device_class_hid_report_id == UX_TRUE) |
101 |
|
|
{ |
102 |
|
|
/* Set the report ID, First byte of data payload. */ |
103 |
|
5 |
hid_event.ux_device_class_hid_event_report_id = (ULONG) *hid_buffer; |
104 |
|
|
|
105 |
|
|
/* Set the length = total length - report ID. */ |
106 |
|
5 |
hid_event.ux_device_class_hid_event_length = transfer_request -> ux_slave_transfer_request_actual_length -1; |
107 |
|
|
|
108 |
|
|
/* Set HID data after report ID. */ |
109 |
|
5 |
hid_buffer++; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
else |
113 |
|
|
{ |
114 |
|
|
/* Set the report ID, not used here. */ |
115 |
|
159 |
hid_event.ux_device_class_hid_event_report_id = 0; |
116 |
|
|
|
117 |
|
|
/* Set the length. */ |
118 |
|
159 |
hid_event.ux_device_class_hid_event_length = transfer_request -> ux_slave_transfer_request_actual_length; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
/* Copy the buffer received from the host. Check for overflow. */ |
122 |
✓✓ |
164 |
if (hid_event.ux_device_class_hid_event_length > UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH) |
123 |
|
|
|
124 |
|
|
/* Overflow detected. */ |
125 |
|
1 |
hid_event.ux_device_class_hid_event_length = UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH; |
126 |
|
|
|
127 |
|
|
/* Now we can safely copy the payload. */ |
128 |
|
164 |
_ux_utility_memory_copy(hid_event.ux_device_class_hid_event_buffer, hid_buffer, |
129 |
|
|
hid_event.ux_device_class_hid_event_length); /* Use case of memcpy is verified. */ |
130 |
|
|
|
131 |
|
|
/* If there is a callback defined by the application, send the hid event to it. */ |
132 |
✓✓ |
164 |
if (hid -> ux_device_class_hid_callback != UX_NULL) |
133 |
|
|
|
134 |
|
|
/* Callback exists. */ |
135 |
|
161 |
hid -> ux_device_class_hid_callback(hid, &hid_event); |
136 |
|
|
|
137 |
|
|
/* Return the status to the caller. */ |
138 |
|
164 |
return(UX_SUCCESS); |
139 |
|
|
} |