2#include "pedigree/kernel/LockGuard.h"
3#include "pedigree/kernel/Log.h"
4#include "pedigree/kernel/machine/InputManager.h"
5#include "pedigree/kernel/process/Mutex.h"
6#include "pedigree/kernel/process/Semaphore.h"
8#include "modules/drivers/common/hid/HidReport.h"
9#include "modules/drivers/common/hid/HidUtils.h"
19 auto* capture =
static_cast<Capture*
>(notification.meta);
21 if (notification.type == InputManager::RawKey &&
22 (notification.data.rawkey.
scancode == 4 || notification.data.rawkey.
scancode == 5 ||
23 notification.data.rawkey.
scancode == 0xe1)) {
24 value = notification.data.rawkey.
scancode * (notification.data.rawkey.
keyUp ? -1 : 1);
25 }
else if (notification.type == InputManager::Mouse && notification.data.pointy.relx == -1) {
27 }
else if (notification.type == InputManager::Mouse) {
28 value = 200 + notification.data.pointy.buttons[0] + 2 * notification.data.pointy.buttons[1];
33 if (capture->count < 32) {
34 capture->values[capture->count++] = value;
36 capture->received.release();
40EXPORTED_PUBLIC
bool runHostedHidReportRegressions() {
41 uint8_t descriptor[] = {0x05, 1, 0x09, 6, 0xa1, 1, 0x85, 1, 0x05, 7, 0x09, 4,
42 0x15, 0, 0x25, 1, 0x75, 1, 0x95, 1, 0x81, 2, 0x75, 7,
43 0x81, 3, 0xc0, 0x05, 1, 0x09, 6, 0xa1, 1, 0x85, 2, 0x05,
44 7, 0x09, 5, 0x15, 0, 0x25, 1, 0x75, 1, 0x95, 1, 0x81,
45 2, 0x75, 7, 0x81, 3, 0xc0, 0x05, 1, 0x09, 2, 0xa1, 1,
46 0x85, 3, 0x09, 0x30, 0x16, 0, 0xf8, 0x26, 0xff, 7, 0x75, 12,
47 0x95, 1, 0x81, 6, 0x75, 4, 0x81, 3, 0xc0};
55 uint8_t packets[][3] = {{1, 1}, {2, 1}, {1}, {1, 0}, {2, 0}, {3, 0xff, 0x0f}};
56 const size_t lengths[] = {2, 2, 1, 2, 2, 3};
57 for (
size_t i = 0; i < 6; ++i)
58 report.
feedInput(packets[i],
nullptr, lengths[i]);
59 bool delivered = capture.received.acquireForCompletion(5, 2);
61 uint8_t hotplugDescriptor[] = {0x05, 1, 0x09, 6, 0xa1, 1, 0x85, 1, 0x05, 7, 0x09,
62 4, 0x09, 0xe1, 0x15, 0, 0x25, 1, 0x75, 1, 0x95, 2,
63 0x81, 2, 0x75, 6, 0x95, 1, 0x81, 3, 0xc0, 0x05, 1,
64 0x09, 2, 0xa1, 1, 0x85, 2, 0x05, 9, 0x19, 1, 0x29,
65 2, 0x15, 0, 0x25, 1, 0x75, 1, 0x95, 2, 0x81, 2,
66 0x75, 6, 0x95, 1, 0x81, 3, 0xc0};
70 second->parseDescriptor(hotplugDescriptor,
sizeof(hotplugDescriptor));
71 uint8_t heldKeys[] = {1, 3};
72 uint8_t left[] = {2, 1};
73 uint8_t both[] = {2, 3};
74 first->feedInput(heldKeys,
nullptr,
sizeof(heldKeys));
75 delivered &= capture.received.acquireForCompletion(2, 2);
76 first->feedInput(left,
nullptr,
sizeof(left));
77 delivered &= capture.received.acquireForCompletion(1, 2);
78 second->feedInput(heldKeys,
nullptr,
sizeof(heldKeys));
79 second->feedInput(left,
nullptr,
sizeof(left));
80 delivered &= capture.received.acquireForCompletion(1, 2);
81 second->feedInput(both,
nullptr,
sizeof(both));
82 delivered &= capture.received.acquireForCompletion(1, 2);
84 delivered &= capture.received.acquireForCompletion(1, 2);
85 uint8_t unshifted[] = {1, 1};
86 uint8_t right[] = {2, 2};
87 second->feedInput(unshifted,
nullptr,
sizeof(unshifted));
88 delivered &= capture.received.acquireForCompletion(1, 2);
89 second->feedInput(right,
nullptr,
sizeof(right));
90 delivered &= capture.received.acquireForCompletion(1, 2);
92 delivered &= capture.received.acquireForCompletion(2, 2);
95 reconnected.
parseDescriptor(hotplugDescriptor,
sizeof(hotplugDescriptor));
96 reconnected.
feedInput(unshifted,
nullptr,
sizeof(unshifted));
98 const int expected[] = {4, 5, -4, -5, 100, 4, 0xe1, 201, 201,
99 203, 203, -0xe1, 202, -4, 200, 4, -4};
100 const size_t expectedCount =
sizeof(expected) /
sizeof(expected[0]);
101 delivered &= capture.received.acquireForCompletion(2, 2);
103 bool valid = delivered && capture.count == expectedCount;
104 for (
size_t i = 0; valid && i < expectedCount; ++i)
105 valid = capture.values[i] == expected[i];
106 uint8_t truncated[] = {0x27, 0};
109 valid &= !malformed.valid();
111 for (
size_t i = 0; i < 34; i += 2) {
117 valid &= !deep.valid();
118 uint8_t field[] = {0xf0, 0x3f};
121 NOTICE(
"HOSTED-WAIT-TEST: PASS hid-report-ids-short-signed-bounds-and-hotplug");
123 ERROR(
"HOSTED-WAIT-TEST: FAIL hid-report-ids-short-signed-bounds-and-hotplug");
void parseDescriptor(uint8_t *pDescriptor, size_t nDescriptorLength)
Parses a HID report descriptor and stores the resulted data.
void feedInput(uint8_t *pBuffer, uint8_t *pOldBuffer, size_t nBufferSize)
Feeds the input interpreter with a new input buffer.
uint64_t getBufferField(uint8_t *pBuffer, size_t nStart, size_t nLength)
Retrieves a field in a buffer.