1 /* 2 * PROJECT: ReactOS InPort (Bus) Mouse Driver 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: I/O control handling 5 * COPYRIGHT: Copyright 2020 Dmitry Borisov (di.sean@protonmail.com) 6 */ 7 8 /* INCLUDES *******************************************************************/ 9 10 #include "inport.h" 11 12 #define NDEBUG 13 #include <debug.h> 14 15 /* FUNCTIONS ******************************************************************/ 16 17 NTSTATUS 18 NTAPI 19 InPortInternalDeviceControl( 20 _In_ PDEVICE_OBJECT DeviceObject, 21 _Inout_ PIRP Irp) 22 { 23 NTSTATUS Status; 24 PCONNECT_DATA ConnectData; 25 PINPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension; 26 PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp); 27 28 DPRINT("%s(%p, %p) 0x%X\n", __FUNCTION__, DeviceObject, Irp, 29 IrpSp->Parameters.DeviceIoControl.IoControlCode); 30 31 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) 32 { 33 case IOCTL_INTERNAL_MOUSE_CONNECT: 34 if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONNECT_DATA)) 35 { 36 Status = STATUS_INVALID_PARAMETER; 37 break; 38 } 39 40 /* Already connected */ 41 if (DeviceExtension->ClassService) 42 { 43 Status = STATUS_SHARING_VIOLATION; 44 break; 45 } 46 47 ConnectData = IrpSp->Parameters.DeviceIoControl.Type3InputBuffer; 48 49 DeviceExtension->ClassDeviceObject = ConnectData->ClassDeviceObject; 50 DeviceExtension->ClassService = ConnectData->ClassService; 51 52 Status = STATUS_SUCCESS; 53 break; 54 55 case IOCTL_INTERNAL_MOUSE_DISCONNECT: 56 DeviceExtension->ClassService = NULL; 57 58 Status = STATUS_SUCCESS; 59 break; 60 61 case IOCTL_MOUSE_QUERY_ATTRIBUTES: 62 if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(MOUSE_ATTRIBUTES)) 63 { 64 Status = STATUS_BUFFER_TOO_SMALL; 65 break; 66 } 67 68 *(PMOUSE_ATTRIBUTES)Irp->AssociatedIrp.SystemBuffer = DeviceExtension->MouseAttributes; 69 Irp->IoStatus.Information = sizeof(MOUSE_ATTRIBUTES); 70 71 Status = STATUS_SUCCESS; 72 break; 73 74 default: 75 Status = STATUS_INVALID_DEVICE_REQUEST; 76 break; 77 } 78 79 Irp->IoStatus.Status = Status; 80 IoCompleteRequest(Irp, IO_NO_INCREMENT); 81 82 return Status; 83 } 84