我参与为 Mac OS 开发自定义 HID 设备支持。但是它不是 HID 投诉,即它被 IOUSBCompositeDriver 抓取。
该设备应该用作输入设备(键盘、鼠标),因此我正在尝试将驱动程序实现为 kext。我试图继承 IOUSBHIDDriver 和 IOHIDDevice 从 newReportDescriptor() 方法返回以下报告描述符(取自 Windows 团队):
const unsigned char g_ReportDescriptor[] = {
// Keyboard report
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x85, REPORTID_KEYBOARD, // REPORT_ID (Keyboard)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x95, 0x05, // REPORT_COUNT (5)
0x75, 0x01, // REPORT_SIZE (1)
0x05, 0x08, // USAGE_PAGE (LEDs)
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
0x29, 0x05, // USAGE_MAXIMUM (Kana)
0x91, 0x02, // OUTPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x03, // REPORT_SIZE (3)
0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
// Relative Mouse report
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x85, REPORTID_RELATIVE_MOUSE, // REPORT_ID (Mouse)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x05, // USAGE_MAXIMUM (Button 5)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x05, // REPORT_COUNT (5)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x06, // INPUT (Data,Var,Rel)
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x38, // Usage (Wheel)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x81, 0x06, // Input (Data, Variable, Relative)
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
// Control report
0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1)
0x09, 0x01, // USAGE (Vendor Usage 1)
0xa1, 0x01, // COLLECTION (Application)
0x85, REPORTID_VXYCONTROL, // REPORT_ID ()
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
0x75, 0x10, // REPORT_SIZE (16)
0x95, 0x02, // REPORT_COUNT (2)
0x09, 0x01, // USAGE (Vendor Usage 1)
0x91, 0x00, // OUTPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
// Trigger Macro report
0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1)
0x09, 0x02, // USAGE (Vendor Usage 2)
0xa1, 0x01, // COLLECTION (Application)
0x85, REPORTID_MACROTRIG, // REPORT_ID (5)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x09, 0x02, // USAGE (Vendor Usage 2)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0 // END_COLLECTION
};
然后将以下结构提供给 handleReport() 方法
#define KBD_KEY_CODES 6
#pragma pack(1)
typedef struct _VHID_KEYBOARD_REPORT
{
UInt8 ReportID;
// Left Control, Left Shift, Left Alt, Left GUI
// Right Control, Right Shift, Right Alt, Right GUI
UInt8 ShiftKeyFlags;
UInt8 Reserved;
UInt8 KeyCodes[KBD_KEY_CODES];
} VHID_KEYBOARD_REPORT;
VHID_KEYBOARD_REPORT keyboardReport;
bzero(&keyboardReport, sizeof(keyboardReport));
keyboardReport.ReportID = REPORTID_KEYBOARD;
keyboardReport.ShiftKeyFlags = 0;
keyboardReport.KeyCodes[0] = kHIDUsage_KeyboardA;
IOBufferMemoryDescriptor *report = IOBufferMemoryDescriptor::withBytes(&keyboardReport, sizeof(keyboardReport), kIODirectionInOut);
handleReport(report);
但是我没有看到任何影响。我预计会生成按键事件。
我错过了什么?这种驱动程序的一般工作流程是什么?