WriteFile to an HID vendor Output report returns 1 because OutputReportByteLength is 0

0

I am trying to get data into my microcontroller over i2c-hid from Windows. What I have is working if I hook up to a linux host (Raspberry PI). But on Windows 10, both WriteFile and HidD_SetOutputReport return 1 (ERROR_INVALID_FUNCTION). I believe this is because the OutputReportByteLength in the CAPS structure returned by HidP_GetCaps is 0 (InputReportByteLength is also 0, same problem). The feature report I have in parallel to these input and output reports has the expected length, and I can get and set feature reports. Why does Windows incorrectly parse my report descriptor? Note that I have tried to rearrange the order of the feature, output, and input sections in my descriptor, and the feature report always works (977 for byte length in CAPS), and the input and output reports always return 0 for byte length in the CAPS structure.

CreateFile

devHandle = CreateFile(currentInterface,
            GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL, // no SECURITY_ATTRIBUTES structure
            OPEN_EXISTING, // No special create flags
            0, // No special attributes
            NULL); // No template file

WriteFile

UINT8 buf[9];
buf[0] = 0x9; // Report ID = 9
success = WriteFile(
        device->file,        // HANDLE hFile,
        buf,      // LPVOID lpBuffer,
        sizeof(buf),  // DWORD nNumberOfBytesToRead,
        &bytes_written,  // LPDWORD lpNumberOfBytesRead,
        NULL         // LPOVERLAPPED lpOverlapped
    );

Report descriptor

//-------------------------------
// Decoded Application Collection
//-------------------------------

/*
06 00FF      (GLOBAL) USAGE_PAGE         0xFF00 Vendor-defined 
09 01        (LOCAL)  USAGE              0xFF000001 
A1 01        (MAIN)   COLLECTION         0x00000001 Application (Usage=0xFF000001: Page=Vendor-defined, Usage=, Type=)
85 01          (GLOBAL) REPORT_ID          0x01 (1) 
09 01          (LOCAL)  USAGE              0xFF000001 <-- Warning: Undocumented usage
14             (GLOBAL) LOGICAL_MINIMUM    (0)  
26 FF00        (GLOBAL) LOGICAL_MAXIMUM    0x00FF (255)  
75 08          (GLOBAL) REPORT_SIZE        0x08 (8) Number of bits per field

96 D003        (GLOBAL) REPORT_COUNT       0x03D0 (976) Number of fields  
B1 02          (MAIN)   FEATURE            0x00000002 (976 fields x 8 bits) 0=Data 1=Variable 0=Absolute 0=NoWrap 0=Linear 0=PrefState 0=NoNull 0=NonVolatile 0=Bitmap 
85 09          (GLOBAL) REPORT_ID          0x09 (9) 
09 01          (LOCAL)  USAGE              0xFF000001 <-- Warning: Undocumented usage
95 08          (GLOBAL) REPORT_COUNT       0x08 (8) Number of fields  
91 02          (MAIN)   OUTPUT             0x00000002 (8 fields x 8 bits) 0=Data 1=Variable 0=Absolute 0=NoWrap 0=Linear 0=PrefState 0=NoNull 0=NonVolatile 0=Bitmap 
09 01          (LOCAL)  USAGE              0xFF000001 <-- Warning: Undocumented usage
95 40          (GLOBAL) REPORT_COUNT       0x40 (64) Number of fields  
81 02          (MAIN)   INPUT              0x00000002 (64 fields x 8 bits) 0=Data 1=Variable 0=Absolute 0=NoWrap 0=Linear 0=PrefState 0=NoNull 0=NonVolatile 0=Bitmap 
C0           (MAIN)   END_COLLECTION     Application 
*/
winapi
hid
wdk
asked on Stack Overflow Feb 24, 2018 by yumbrad

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0