@@ -805,40 +805,48 @@ Return Value:
805805--*/
806806{
807807 NTSTATUS status ;
808- HID_XFER_PACKET packet ;
809- ULONG i ;
810- ULONG scan ;
808+ WDFMEMORY inputMemory ;
809+ size_t inputLen = 0 ;
810+ PUCHAR inputBuf ;
811+ size_t i ;
812+ size_t scan ;
811813
812814 KdPrint (("SetFeature\n" ));
813815
814- status = RequestGetHidXferPacket_ToWriteToDevice (
815- Request ,
816- & packet );
817- if ( !NT_SUCCESS (status ) ) {
816+ //
817+ // Read the feature report data directly. We deliberately do NOT use
818+ // RequestGetHidXferPacket_ToWriteToDevice() here: that helper derives the
819+ // report id from the request's *output* buffer length, which is 0 for an
820+ // unnumbered device (report id 0) and makes the retrieval fail. We only
821+ // need the raw bytes.
822+ //
823+ status = WdfRequestRetrieveInputMemory (Request , & inputMemory );
824+ if (!NT_SUCCESS (status )) {
818825 return status ;
819826 }
827+ inputBuf = (PUCHAR )WdfMemoryGetBuffer (inputMemory , & inputLen );
820828
821829 //
822830 // HIDAPI test: a Feature report carries a scenario command. Depending on
823- // whether the report is numbered , the command may be prefixed by a
824- // report-id byte, so scan the first few bytes for a recognised command
825- // (the report-id byte is 0 for this unnumbered device and the commands are
826- // non-zero, so this is unambiguous). The matching input report is replayed
827- // by the manual-queue timer (EvtTimerFunc).
831+ // whether the report is prefixed by a report-id byte , the command is in the
832+ // first couple of bytes; scan for a recognised TEST_VDEV_CMD_* value (the
833+ // report-id byte is 0 and the commands are non-zero, so this is
834+ // unambiguous). The matching input report is replayed by the manual-queue
835+ // timer (EvtTimerFunc).
828836 //
829- scan = packet . reportBufferLen ;
837+ scan = inputLen ;
830838 if (scan > 4 ) {
831839 scan = 4 ;
832840 }
833841 for (i = 0 ; i < scan ; i ++ ) {
834- UCHAR b = packet . reportBuffer [i ];
842+ UCHAR b = inputBuf [i ];
835843 if (b == TEST_VDEV_CMD_EMIT_A || b == TEST_VDEV_CMD_EMIT_B ) {
836844 InterlockedExchange (& QueueContext -> DeviceContext -> ScenarioCommand , (LONG )b );
837845 break ;
838846 }
839847 }
840848
841- WdfRequestSetInformation (Request , packet . reportBufferLen );
849+ WdfRequestSetInformation (Request , inputLen );
842850 return STATUS_SUCCESS ;
843851}
844852
@@ -1313,7 +1321,7 @@ Return Value:
13131321 PMANUAL_QUEUE_CONTEXT queueContext ;
13141322 WDFREQUEST request ;
13151323 LONG command ;
1316- UCHAR inputReport [TEST_VDEV_REPORT_SIZE ];
1324+ UCHAR inputReport [1 + TEST_VDEV_REPORT_SIZE ]; /* report id + payload */
13171325 static const UCHAR inputA [TEST_VDEV_REPORT_SIZE ] = { TEST_VDEV_INPUT_A_BYTES };
13181326 static const UCHAR inputB [TEST_VDEV_REPORT_SIZE ] = { TEST_VDEV_INPUT_B_BYTES };
13191327
@@ -1341,11 +1349,12 @@ Return Value:
13411349 return ;
13421350 }
13431351
1344- RtlCopyMemory (inputReport ,
1352+ inputReport [0 ] = 0 ; /* report id (the device is unnumbered) */
1353+ RtlCopyMemory (inputReport + 1 ,
13451354 (command == TEST_VDEV_CMD_EMIT_B ) ? inputB : inputA ,
13461355 TEST_VDEV_REPORT_SIZE );
13471356
1348- status = RequestCopyFromBuffer (request , inputReport , TEST_VDEV_REPORT_SIZE );
1357+ status = RequestCopyFromBuffer (request , inputReport , sizeof ( inputReport ) );
13491358 WdfRequestComplete (request , status );
13501359}
13511360
0 commit comments