- Update to r53061
[reactos.git] / drivers / input / sermouse / internaldevctl.c
1 /*
2 * PROJECT: ReactOS Serial mouse driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/input/sermouse/fdo.c
5 * PURPOSE: IRP_MJ_INTERNAL_DEVICE_CONTROL operations
6 * PROGRAMMERS: Copyright 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
9 #include "sermouse.h"
10
11 NTSTATUS NTAPI
12 SermouseInternalDeviceControl(
13 IN PDEVICE_OBJECT DeviceObject,
14 IN PIRP Irp)
15 {
16 PSERMOUSE_DEVICE_EXTENSION DeviceExtension;
17 PIO_STACK_LOCATION Stack;
18 NTSTATUS Status;
19
20 DeviceExtension = (PSERMOUSE_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
21 Stack = IoGetCurrentIrpStackLocation(Irp);
22
23 switch (Stack->Parameters.DeviceIoControl.IoControlCode)
24 {
25 case IOCTL_INTERNAL_MOUSE_CONNECT:
26 {
27 TRACE_(SERMOUSE, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_MOUSE_CONNECT\n");
28 DeviceExtension->ConnectData =
29 *((PCONNECT_DATA)Stack->Parameters.DeviceIoControl.Type3InputBuffer);
30 Status = STATUS_SUCCESS;
31 break;
32 }
33 case IOCTL_INTERNAL_MOUSE_DISCONNECT:
34 {
35 TRACE_(SERMOUSE, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_MOUSE_DISCONNECT\n");
36
37 /* Ask read loop to end */
38 KeSetEvent(&DeviceExtension->StopWorkerThreadEvent, (KPRIORITY)0, FALSE);
39 Status = STATUS_SUCCESS;
40 break;
41 }
42 case IOCTL_MOUSE_QUERY_ATTRIBUTES:
43 {
44 TRACE_(SERMOUSE, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_MOUSE_QUERY_ATTRIBUTES\n");
45 if (Stack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(MOUSE_ATTRIBUTES))
46 {
47 *(PMOUSE_ATTRIBUTES)Irp->AssociatedIrp.SystemBuffer =
48 DeviceExtension->AttributesInformation;
49 Irp->IoStatus.Information = sizeof(MOUSE_ATTRIBUTES);
50 Status = STATUS_SUCCESS;
51 }
52 else
53 {
54 Status = STATUS_BUFFER_TOO_SMALL;
55 }
56 break;
57 }
58 default:
59 {
60 WARN_(SERMOUSE, "IRP_MJ_INTERNAL_DEVICE_CONTROL / unknown ioctl code 0x%lx\n",
61 Stack->Parameters.DeviceIoControl.IoControlCode);
62 ASSERT(FALSE);
63 Status = STATUS_INVALID_DEVICE_REQUEST;
64 break;
65 }
66 }
67
68 Irp->IoStatus.Status = Status;
69 if (Status == STATUS_PENDING)
70 {
71 IoMarkIrpPending(Irp);
72 IoStartPacket(DeviceObject, Irp, NULL, NULL);
73 }
74 else
75 {
76 IoCompleteRequest(Irp, IO_NO_INCREMENT);
77 }
78
79 return Status;
80 }