2 * PROJECT: ReactOS HID Stack
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/hid/mouhid/mouhid.c
5 * PURPOSE: Mouse HID Driver
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
13 static USHORT MouHid_ButtonDownFlags
[] =
15 MOUSE_LEFT_BUTTON_DOWN
,
16 MOUSE_RIGHT_BUTTON_DOWN
,
17 MOUSE_MIDDLE_BUTTON_DOWN
,
22 static USHORT MouHid_ButtonUpFlags
[] =
25 MOUSE_RIGHT_BUTTON_UP
,
26 MOUSE_MIDDLE_BUTTON_UP
,
33 IN PMOUHID_DEVICE_EXTENSION DeviceExtension
,
43 /* get scaled usage value x */
44 Status
= HidP_GetScaledUsageValue(HidP_Input
, HID_USAGE_PAGE_GENERIC
, HIDP_LINK_COLLECTION_UNSPECIFIED
, HID_USAGE_GENERIC_X
, (PLONG
)&LastX
, DeviceExtension
->PreparsedData
, DeviceExtension
->Report
, DeviceExtension
->ReportLength
);
45 /* FIXME handle error */
46 ASSERT(Status
== HIDP_STATUS_SUCCESS
);
48 /* get scaled usage value y */
49 Status
= HidP_GetScaledUsageValue(HidP_Input
, HID_USAGE_PAGE_GENERIC
, HIDP_LINK_COLLECTION_UNSPECIFIED
, HID_USAGE_GENERIC_Y
, (PLONG
)&LastY
, DeviceExtension
->PreparsedData
, DeviceExtension
->Report
, DeviceExtension
->ReportLength
);
50 /* FIXME handle error */
51 ASSERT(Status
== HIDP_STATUS_SUCCESS
);
57 MouHid_GetButtonFlags(
58 IN PMOUHID_DEVICE_EXTENSION DeviceExtension
,
59 OUT PUSHORT ButtonFlags
)
65 ULONG CurrentUsageListLength
;
71 CurrentUsageListLength
= DeviceExtension
->UsageListLength
;
72 Status
= HidP_GetUsages(HidP_Input
, HID_USAGE_PAGE_BUTTON
, HIDP_LINK_COLLECTION_UNSPECIFIED
, DeviceExtension
->CurrentUsageList
, &CurrentUsageListLength
, DeviceExtension
->PreparsedData
, DeviceExtension
->Report
, DeviceExtension
->ReportLength
);
73 if (Status
!= HIDP_STATUS_SUCCESS
)
75 DPRINT1("MouHid_GetButtonFlags failed to get usages with %x\n", Status
);
79 /* extract usage list difference */
80 Status
= HidP_UsageListDifference(DeviceExtension
->PreviousUsageList
, DeviceExtension
->CurrentUsageList
, DeviceExtension
->BreakUsageList
, DeviceExtension
->MakeUsageList
, DeviceExtension
->UsageListLength
);
81 if (Status
!= HIDP_STATUS_SUCCESS
)
83 DPRINT1("MouHid_GetButtonFlags failed to get usages with %x\n", Status
);
87 if (DeviceExtension
->UsageListLength
)
93 Usage
= DeviceExtension
->BreakUsageList
[Index
];
99 /* max 5 buttons supported */
100 *ButtonFlags
|= MouHid_ButtonDownFlags
[Usage
];
103 /* move to next index*/
105 }while(Index
< DeviceExtension
->UsageListLength
);
108 if (DeviceExtension
->UsageListLength
)
114 Usage
= DeviceExtension
->MakeUsageList
[Index
];
120 /* max 5 buttons supported */
121 *ButtonFlags
|= MouHid_ButtonUpFlags
[Usage
];
124 /* move to next index*/
126 }while(Index
< DeviceExtension
->UsageListLength
);
129 /* now switch the previous list with current list */
130 TempList
= DeviceExtension
->CurrentUsageList
;
131 DeviceExtension
->CurrentUsageList
= DeviceExtension
->PreviousUsageList
;
132 DeviceExtension
->PreviousUsageList
= TempList
;
136 MouHid_DispatchInputData(
137 IN PMOUHID_DEVICE_EXTENSION DeviceExtension
,
138 IN PMOUSE_INPUT_DATA InputData
)
141 ULONG InputDataConsumed
;
143 if (!DeviceExtension
->ClassService
)
147 ASSERT(DeviceExtension
->ClassService
);
148 ASSERT(DeviceExtension
->ClassDeviceObject
);
151 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
153 /* dispatch input data */
154 (*(PSERVICE_CALLBACK_ROUTINE
)DeviceExtension
->ClassService
)(DeviceExtension
->ClassDeviceObject
, InputData
, InputData
+ 1, &InputDataConsumed
);
156 /* lower irql to previous level */
157 KeLowerIrql(OldIrql
);
162 MouHid_ReadCompletion(
163 IN PDEVICE_OBJECT DeviceObject
,
167 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
172 MOUSE_INPUT_DATA MouseInputData
;
174 /* get device extension */
175 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)Context
;
177 if (Irp
->IoStatus
.Status
== STATUS_PRIVILEGE_NOT_HELD
||
178 Irp
->IoStatus
.Status
== STATUS_DEVICE_NOT_CONNECTED
||
179 Irp
->IoStatus
.Status
== STATUS_CANCELLED
||
180 DeviceExtension
->StopReadReport
)
182 /* failed to read or should be stopped*/
183 DPRINT1("[MOUHID] ReadCompletion terminating read Status %x\n", Irp
->IoStatus
.Status
);
185 /* report no longer active */
186 DeviceExtension
->ReadReportActive
= FALSE
;
188 /* request stopping of the report cycle */
189 DeviceExtension
->StopReadReport
= FALSE
;
191 /* signal completion event */
192 KeSetEvent(&DeviceExtension
->ReadCompletionEvent
, 0, 0);
193 return STATUS_MORE_PROCESSING_REQUIRED
;
196 /* get mouse change flags */
197 MouHid_GetButtonFlags(DeviceExtension
, &ButtonFlags
);
199 /* get mouse change */
200 MouHid_GetButtonMove(DeviceExtension
, &LastX
, &LastY
);
202 /* init input data */
203 RtlZeroMemory(&MouseInputData
, sizeof(MOUSE_INPUT_DATA
));
205 /* init input data */
206 MouseInputData
.ButtonFlags
= ButtonFlags
;
207 MouseInputData
.LastX
= LastX
;
208 MouseInputData
.LastY
= LastY
;
210 /* detect mouse wheel change */
211 if (DeviceExtension
->MouseIdentifier
== WHEELMOUSE_HID_HARDWARE
)
215 Status
= HidP_GetScaledUsageValue(HidP_Input
, HID_USAGE_PAGE_GENERIC
, HIDP_LINK_COLLECTION_UNSPECIFIED
, HID_USAGE_GENERIC_WHEEL
, &UsageValue
, DeviceExtension
->PreparsedData
, DeviceExtension
->Report
, DeviceExtension
->ReportLength
);
216 if (Status
== HIDP_STATUS_SUCCESS
)
218 /* store wheel status */
219 MouseInputData
.ButtonFlags
|= MOUSE_WHEEL
;
220 MouseInputData
.ButtonData
= (USHORT
)UsageValue
; /* FIXME */
224 DPRINT1("[MOUHID] failed to get wheel status with %x\n", Status
);
228 DPRINT1("[MOUHID] LastX %lu LastY %lu Flags %x ButtonData %x\n", MouseInputData
.LastX
, MouseInputData
.LastY
, MouseInputData
.ButtonFlags
, MouseInputData
.ButtonData
);
230 /* dispatch mouse action */
231 MouHid_DispatchInputData(DeviceExtension
, &MouseInputData
);
234 MouHid_InitiateRead(DeviceExtension
);
236 /* stop completion */
237 return STATUS_MORE_PROCESSING_REQUIRED
;
242 IN PMOUHID_DEVICE_EXTENSION DeviceExtension
)
244 PIO_STACK_LOCATION IoStack
;
248 IoReuseIrp(DeviceExtension
->Irp
, STATUS_SUCCESS
);
251 DeviceExtension
->Irp
->MdlAddress
= DeviceExtension
->ReportMDL
;
253 /* get next stack location */
254 IoStack
= IoGetNextIrpStackLocation(DeviceExtension
->Irp
);
256 /* init stack location */
257 IoStack
->Parameters
.Read
.Length
= DeviceExtension
->ReportLength
;
258 IoStack
->Parameters
.Read
.Key
= 0;
259 IoStack
->Parameters
.Read
.ByteOffset
.QuadPart
= 0LL;
260 IoStack
->MajorFunction
= IRP_MJ_READ
;
261 IoStack
->FileObject
= DeviceExtension
->FileObject
;
263 /* set completion routine */
264 IoSetCompletionRoutine(DeviceExtension
->Irp
, MouHid_ReadCompletion
, DeviceExtension
, TRUE
, TRUE
, TRUE
);
267 DeviceExtension
->ReadReportActive
= TRUE
;
270 Status
= IoCallDriver(DeviceExtension
->NextDeviceObject
, DeviceExtension
->Irp
);
278 MouHid_CreateCompletion(
279 IN PDEVICE_OBJECT DeviceObject
,
283 KeSetEvent((PKEVENT
)Context
, 0, FALSE
);
284 return STATUS_MORE_PROCESSING_REQUIRED
;
291 IN PDEVICE_OBJECT DeviceObject
,
294 PIO_STACK_LOCATION IoStack
;
297 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
299 DPRINT1("MOUHID: IRP_MJ_CREATE\n");
301 /* get device extension */
302 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
304 /* get stack location */
305 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
307 /* copy stack location to next */
308 IoCopyCurrentIrpStackLocationToNext(Irp
);
311 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
314 IoSetCompletionRoutine(Irp
, MouHid_CreateCompletion
, &Event
, TRUE
, TRUE
, TRUE
);
316 /* call lower driver */
317 Status
= IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
318 if (Status
== STATUS_PENDING
)
320 /* request pending */
321 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
324 /* check for success */
325 if (!NT_SUCCESS(Status
))
328 Irp
->IoStatus
.Status
= Status
;
329 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
333 /* is the driver already in use */
334 if (DeviceExtension
->FileObject
== NULL
)
336 /* did the caller specify correct attributes */
337 ASSERT(IoStack
->Parameters
.Create
.SecurityContext
);
338 if (IoStack
->Parameters
.Create
.SecurityContext
->DesiredAccess
)
340 /* store file object */
341 DeviceExtension
->FileObject
= IoStack
->FileObject
;
344 KeResetEvent(&DeviceExtension
->ReadCompletionEvent
);
346 /* initiating read */
347 Status
= MouHid_InitiateRead(DeviceExtension
);
348 DPRINT1("[MOUHID] MouHid_InitiateRead: status %x\n", Status
);
349 if (Status
== STATUS_PENDING
)
351 /* report irp is pending */
352 Status
= STATUS_SUCCESS
;
357 /* complete request */
358 Irp
->IoStatus
.Status
= Status
;
359 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
367 IN PDEVICE_OBJECT DeviceObject
,
370 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
372 /* get device extension */
373 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
375 DPRINT("[MOUHID] IRP_MJ_CLOSE ReadReportActive %x\n", DeviceExtension
->ReadReportActive
);
377 if (DeviceExtension
->ReadReportActive
)
379 /* request stopping of the report cycle */
380 DeviceExtension
->StopReadReport
= TRUE
;
382 /* wait until the reports have been read */
383 KeWaitForSingleObject(&DeviceExtension
->ReadCompletionEvent
, Executive
, KernelMode
, FALSE
, NULL
);
386 IoCancelIrp(DeviceExtension
->Irp
);
389 DPRINT("[MOUHID] IRP_MJ_CLOSE ReadReportActive %x\n", DeviceExtension
->ReadReportActive
);
391 /* remove file object */
392 DeviceExtension
->FileObject
= NULL
;
395 IoSkipCurrentIrpStackLocation(Irp
);
397 /* pass irp to down the stack */
398 return IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
403 MouHid_DeviceControl(
404 IN PDEVICE_OBJECT DeviceObject
,
407 PIO_STACK_LOCATION IoStack
;
408 PMOUSE_ATTRIBUTES Attributes
;
409 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
412 /* get current stack location */
413 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
415 /* get device extension */
416 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
418 /* handle requests */
419 if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_MOUSE_QUERY_ATTRIBUTES
)
421 /* verify output buffer length */
422 if (IoStack
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(MOUSE_ATTRIBUTES
))
424 /* invalid request */
425 Irp
->IoStatus
.Status
= STATUS_BUFFER_TOO_SMALL
;
426 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
427 return STATUS_BUFFER_TOO_SMALL
;
430 /* get output buffer */
431 Attributes
= (PMOUSE_ATTRIBUTES
)Irp
->AssociatedIrp
.SystemBuffer
;
434 Attributes
->MouseIdentifier
= DeviceExtension
->MouseIdentifier
;
436 /* number of buttons */
437 Attributes
->NumberOfButtons
= DeviceExtension
->UsageListLength
;
439 /* sample rate not used for usb */
440 Attributes
->SampleRate
= 0;
443 Attributes
->InputDataQueueLength
= 2;
445 /* complete request */
446 Irp
->IoStatus
.Information
= sizeof(MOUSE_ATTRIBUTES
);
447 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
448 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
449 return STATUS_SUCCESS
;
451 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_MOUSE_CONNECT
)
453 /* verify input buffer length */
454 if (IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(CONNECT_DATA
))
456 /* invalid request */
457 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
458 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
459 return STATUS_INVALID_PARAMETER
;
462 /* is it already connected */
463 if (DeviceExtension
->ClassService
)
465 /* already connected */
466 Irp
->IoStatus
.Status
= STATUS_SHARING_VIOLATION
;
467 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
468 return STATUS_SHARING_VIOLATION
;
471 /* get connect data */
472 Data
= (PCONNECT_DATA
)IoStack
->Parameters
.DeviceIoControl
.Type3InputBuffer
;
474 /* store connect details */
475 DeviceExtension
->ClassDeviceObject
= Data
->ClassDeviceObject
;
476 DeviceExtension
->ClassService
= Data
->ClassService
;
478 /* completed successfully */
479 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
480 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
481 return STATUS_SUCCESS
;
483 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_MOUSE_DISCONNECT
)
486 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
487 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
488 return STATUS_NOT_IMPLEMENTED
;
490 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_MOUSE_ENABLE
)
493 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
494 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
495 return STATUS_NOT_SUPPORTED
;
497 else if (IoStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_INTERNAL_MOUSE_DISABLE
)
500 Irp
->IoStatus
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
501 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
502 return STATUS_INVALID_DEVICE_REQUEST
;
505 /* unknown request not supported */
506 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
507 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
508 return STATUS_NOT_SUPPORTED
;
513 MouHid_InternalDeviceControl(
514 IN PDEVICE_OBJECT DeviceObject
,
517 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
519 /* get device extension */
520 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
522 /* skip stack location */
523 IoSkipCurrentIrpStackLocation(Irp
);
525 /* pass and forget */
526 return IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
532 IN PDEVICE_OBJECT DeviceObject
,
537 return STATUS_NOT_IMPLEMENTED
;
541 MouHid_SubmitRequest(
542 PDEVICE_OBJECT DeviceObject
,
544 ULONG InputBufferSize
,
546 ULONG OutputBufferSize
,
550 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
553 IO_STATUS_BLOCK IoStatus
;
555 /* get device extension */
556 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
559 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
562 Irp
= IoBuildDeviceIoControlRequest(IoControlCode
, DeviceExtension
->NextDeviceObject
, InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
, FALSE
, &Event
, &IoStatus
);
566 return STATUS_INSUFFICIENT_RESOURCES
;
570 Status
= IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
571 if (Status
== STATUS_PENDING
)
573 /* wait for request to complete */
574 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
575 Status
= IoStatus
.Status
;
585 IN PDEVICE_OBJECT DeviceObject
)
589 HID_COLLECTION_INFORMATION Information
;
591 HIDP_CAPS Capabilities
;
592 ULONG ValueCapsLength
;
593 HIDP_VALUE_CAPS ValueCaps
;
594 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
597 /* get device extension */
598 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
600 /* query collection information */
601 Status
= MouHid_SubmitRequest(DeviceObject
, IOCTL_HID_GET_COLLECTION_INFORMATION
, 0, NULL
, sizeof(HID_COLLECTION_INFORMATION
), &Information
);
602 if (!NT_SUCCESS(Status
))
604 /* failed to query collection information */
605 DPRINT1("[MOUHID] failed to obtain collection information with %x\n", Status
);
609 /* lets allocate space for preparsed data */
610 PreparsedData
= ExAllocatePool(NonPagedPool
, Information
.DescriptorSize
);
614 DPRINT1("[MOUHID] no memory size %u\n", Information
.DescriptorSize
);
615 return STATUS_INSUFFICIENT_RESOURCES
;
618 /* now obtain the preparsed data */
619 Status
= MouHid_SubmitRequest(DeviceObject
, IOCTL_HID_GET_COLLECTION_DESCRIPTOR
, 0, NULL
, Information
.DescriptorSize
, PreparsedData
);
620 if (!NT_SUCCESS(Status
))
622 /* failed to get preparsed data */
623 DPRINT1("[MOUHID] failed to obtain collection information with %x\n", Status
);
624 ExFreePool(PreparsedData
);
628 /* lets get the caps */
629 Status
= HidP_GetCaps(PreparsedData
, &Capabilities
);
630 if (!NT_SUCCESS(Status
))
632 /* failed to get capabilities */
633 DPRINT1("[MOUHID] failed to obtain caps with %x\n", Status
);
634 ExFreePool(PreparsedData
);
638 DPRINT1("[MOUHID] Usage %x UsagePage %x\n", Capabilities
.Usage
, Capabilities
.UsagePage
, Capabilities
.InputReportByteLength
);
640 /* verify capabilities */
641 if (Capabilities
.Usage
!= HID_USAGE_GENERIC_POINTER
&& Capabilities
.Usage
!= HID_USAGE_GENERIC_MOUSE
|| Capabilities
.UsagePage
!= HID_USAGE_PAGE_GENERIC
)
644 ExFreePool(PreparsedData
);
645 return STATUS_UNSUCCESSFUL
;
648 /* init input report*/
649 DeviceExtension
->ReportLength
= Capabilities
.InputReportByteLength
;
650 ASSERT(DeviceExtension
->ReportLength
);
651 DeviceExtension
->Report
= (PUCHAR
)ExAllocatePool(NonPagedPool
, DeviceExtension
->ReportLength
);
652 ASSERT(DeviceExtension
->Report
);
653 RtlZeroMemory(DeviceExtension
->Report
, DeviceExtension
->ReportLength
);
656 DeviceExtension
->ReportMDL
= IoAllocateMdl(DeviceExtension
->Report
, DeviceExtension
->ReportLength
, FALSE
, FALSE
, NULL
);
657 ASSERT(DeviceExtension
->ReportMDL
);
660 MmBuildMdlForNonPagedPool(DeviceExtension
->ReportMDL
);
662 /* get max number of buttons */
663 Buttons
= HidP_MaxUsageListLength(HidP_Input
, HID_USAGE_PAGE_BUTTON
, PreparsedData
);
664 DPRINT1("[MOUHID] Buttons %lu\n", Buttons
);
667 /* now allocate an array for those buttons */
668 Buffer
= ExAllocatePool(NonPagedPool
, sizeof(USAGE
) * 4 * Buttons
);
672 ExFreePool(PreparsedData
);
673 return STATUS_INSUFFICIENT_RESOURCES
;
676 /* init usage lists */
677 RtlZeroMemory(Buffer
, sizeof(USAGE
) * 4 * Buttons
);
678 DeviceExtension
->CurrentUsageList
= Buffer
;
680 DeviceExtension
->PreviousUsageList
= Buffer
;
682 DeviceExtension
->MakeUsageList
= Buffer
;
684 DeviceExtension
->BreakUsageList
= Buffer
;
686 /* store number of buttons */
687 DeviceExtension
->UsageListLength
= (USHORT
)Buttons
;
689 /* store preparsed data */
690 DeviceExtension
->PreparsedData
= PreparsedData
;
693 HidP_GetSpecificValueCaps(HidP_Input
, HID_USAGE_PAGE_GENERIC
, HIDP_LINK_COLLECTION_UNSPECIFIED
, HID_USAGE_GENERIC_X
, &ValueCaps
, &ValueCapsLength
, PreparsedData
);
696 HidP_GetSpecificValueCaps(HidP_Input
, HID_USAGE_PAGE_GENERIC
, HIDP_LINK_COLLECTION_UNSPECIFIED
, HID_USAGE_GENERIC_Y
, &ValueCaps
, &ValueCapsLength
, PreparsedData
);
698 /* now check for wheel mouse support */
700 Status
= HidP_GetSpecificValueCaps(HidP_Input
, HID_USAGE_PAGE_GENERIC
, HIDP_LINK_COLLECTION_UNSPECIFIED
, HID_USAGE_GENERIC_WHEEL
, &ValueCaps
, &ValueCapsLength
, PreparsedData
);
701 if (Status
== HIDP_STATUS_SUCCESS
)
703 /* mouse has wheel support */
704 DeviceExtension
->MouseIdentifier
= WHEELMOUSE_HID_HARDWARE
;
705 DeviceExtension
->WheelUsagePage
= ValueCaps
.UsagePage
;
706 DPRINT1("[MOUHID] mouse wheel support detected\n", Status
);
710 /* check if the mouse has z-axis */
712 Status
= HidP_GetSpecificValueCaps(HidP_Input
, HID_USAGE_PAGE_GENERIC
, HIDP_LINK_COLLECTION_UNSPECIFIED
, HID_USAGE_GENERIC_Z
, &ValueCaps
, &ValueCapsLength
, PreparsedData
);
713 if (Status
== HIDP_STATUS_SUCCESS
&& ValueCapsLength
== 1)
716 DeviceExtension
->MouseIdentifier
= WHEELMOUSE_HID_HARDWARE
;
717 DeviceExtension
->WheelUsagePage
= ValueCaps
.UsagePage
;
718 DPRINT1("[MOUHID] mouse wheel support detected with z-axis\n", Status
);
722 /* completed successfully */
723 return STATUS_SUCCESS
;
728 MouHid_StartDeviceCompletion(
729 IN PDEVICE_OBJECT DeviceObject
,
733 KeSetEvent((PKEVENT
)Context
, 0, FALSE
);
734 return STATUS_MORE_PROCESSING_REQUIRED
;
740 IN PDEVICE_OBJECT DeviceObject
,
743 PIO_STACK_LOCATION IoStack
;
746 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
748 /* get device extension */
749 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
751 /* get current irp stack */
752 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
754 if (IoStack
->MinorFunction
== IRP_MN_STOP_DEVICE
|| IoStack
->MinorFunction
== IRP_MN_CANCEL_REMOVE_DEVICE
|| IoStack
->MinorFunction
== IRP_MN_QUERY_STOP_DEVICE
|| IoStack
->MinorFunction
== IRP_MN_CANCEL_STOP_DEVICE
)
756 /* indicate success */
757 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
759 /* skip irp stack location */
760 IoSkipCurrentIrpStackLocation(Irp
);
762 /* dispatch to lower device */
763 return IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
765 else if (IoStack
->MinorFunction
== IRP_MN_REMOVE_DEVICE
)
767 /* FIXME synchronization */
770 IoCancelIrp(DeviceExtension
->Irp
);
772 /* indicate success */
773 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
775 /* skip irp stack location */
776 IoSkipCurrentIrpStackLocation(Irp
);
778 /* dispatch to lower device */
779 Status
= IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
781 IoFreeIrp(DeviceExtension
->Irp
);
782 IoDetachDevice(DeviceExtension
->NextDeviceObject
);
783 IoDeleteDevice(DeviceObject
);
786 else if (IoStack
->MinorFunction
== IRP_MN_START_DEVICE
)
789 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
791 /* copy stack location */
792 IoCopyCurrentIrpStackLocationToNext (Irp
);
794 /* set completion routine */
795 IoSetCompletionRoutine(Irp
, MouHid_StartDeviceCompletion
, &Event
, TRUE
, TRUE
, TRUE
);
796 Irp
->IoStatus
.Status
= 0;
799 Status
= IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
800 if (Status
== STATUS_PENDING
)
802 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
803 Status
= Irp
->IoStatus
.Status
;
806 if (!NT_SUCCESS(Status
))
809 Irp
->IoStatus
.Status
= Status
;
810 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
814 /* lets start the device */
815 Status
= MouHid_StartDevice(DeviceObject
);
816 DPRINT1("MouHid_StartDevice %x\n", Status
);
818 /* complete request */
819 Irp
->IoStatus
.Status
= Status
;
820 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
827 /* skip irp stack location */
828 IoSkipCurrentIrpStackLocation(Irp
);
830 /* dispatch to lower device */
831 return IoCallDriver(DeviceExtension
->NextDeviceObject
, Irp
);
838 IN PDRIVER_OBJECT DriverObject
,
839 IN PDEVICE_OBJECT PhysicalDeviceObject
)
842 PDEVICE_OBJECT DeviceObject
, NextDeviceObject
;
843 PMOUHID_DEVICE_EXTENSION DeviceExtension
;
846 /* create device object */
847 Status
= IoCreateDevice(DriverObject
, sizeof(MOUHID_DEVICE_EXTENSION
), NULL
, FILE_DEVICE_MOUSE
, 0, FALSE
, &DeviceObject
);
848 if (!NT_SUCCESS(Status
))
850 /* failed to create device object */
855 NextDeviceObject
= IoAttachDeviceToDeviceStack(DeviceObject
, PhysicalDeviceObject
);
856 if (!NextDeviceObject
)
858 /* failed to attach */
859 IoDeleteDevice(DeviceObject
);
860 return STATUS_DEVICE_NOT_CONNECTED
;
863 /* get device extension */
864 DeviceExtension
= (PMOUHID_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
867 RtlZeroMemory(DeviceExtension
, sizeof(MOUHID_DEVICE_EXTENSION
));
869 /* init device extension */
870 DeviceExtension
->MouseIdentifier
= MOUSE_HID_HARDWARE
;
871 DeviceExtension
->WheelUsagePage
= 0;
872 DeviceExtension
->NextDeviceObject
= NextDeviceObject
;
873 KeInitializeEvent(&DeviceExtension
->ReadCompletionEvent
, NotificationEvent
, FALSE
);
874 DeviceExtension
->Irp
= IoAllocateIrp(NextDeviceObject
->StackSize
, FALSE
);
876 /* FIXME handle allocation error */
877 ASSERT(DeviceExtension
->Irp
);
879 /* FIXME query parameter 'FlipFlopWheel', 'WheelScalingFactor' */
881 /* set power state to D0 */
882 State
.DeviceState
= PowerDeviceD0
;
883 PoSetPowerState(DeviceObject
, DevicePowerState
, State
);
885 /* init device object */
886 DeviceObject
->Flags
|= DO_BUFFERED_IO
| DO_POWER_PAGABLE
;
887 DeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
889 /* completed successfully */
890 return STATUS_SUCCESS
;
896 IN PDRIVER_OBJECT DriverObject
)
906 IN PDRIVER_OBJECT DriverObject
,
907 IN PUNICODE_STRING RegPath
)
909 /* FIXME check for parameters 'UseOnlyMice', 'TreatAbsoluteAsRelative', 'TreatAbsolutePointerAsAbsolute' */
911 /* initialize driver object */
912 DriverObject
->DriverUnload
= MouHid_Unload
;
913 DriverObject
->DriverExtension
->AddDevice
= MouHid_AddDevice
;
914 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = MouHid_Create
;
915 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = MouHid_Close
;
916 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = MouHid_DeviceControl
;
917 DriverObject
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = MouHid_InternalDeviceControl
;
918 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = MouHid_Power
;
919 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = MouHid_Pnp
;
920 DriverObject
->DriverUnload
= MouHid_Unload
;
921 DriverObject
->DriverExtension
->AddDevice
= MouHid_AddDevice
;
924 return STATUS_SUCCESS
;