2 * WINE Hid device services
4 * Copyright 2015 Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
27 #include "wine/list.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(hid
);
31 static struct list minidriver_list
= LIST_INIT(minidriver_list
);
33 minidriver
* find_minidriver(DRIVER_OBJECT
*driver
)
36 LIST_FOR_EACH_ENTRY(md
, &minidriver_list
, minidriver
, entry
)
38 if (md
->minidriver
.DriverObject
== driver
)
44 static VOID WINAPI
UnloadDriver(DRIVER_OBJECT
*driver
)
48 TRACE("Driver Unload\n");
49 md
= find_minidriver(driver
);
53 md
->DriverUnload(md
->minidriver
.DriverObject
);
54 PNP_CleanupPNP(md
->minidriver
.DriverObject
);
55 list_remove(&md
->entry
);
56 HeapFree( GetProcessHeap(), 0, md
);
60 NTSTATUS WINAPI
HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION
*registration
)
63 driver
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*driver
));
66 return STATUS_NO_MEMORY
;
68 driver
->DriverUnload
= registration
->DriverObject
->DriverUnload
;
69 registration
->DriverObject
->DriverUnload
= UnloadDriver
;
71 registration
->DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = HID_Device_ioctl
;
72 registration
->DriverObject
->MajorFunction
[IRP_MJ_READ
] = HID_Device_read
;
73 registration
->DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = HID_Device_write
;
74 registration
->DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = HID_Device_create
;
75 registration
->DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = HID_Device_close
;
77 driver
->AddDevice
= registration
->DriverObject
->DriverExtension
->AddDevice
;
78 registration
->DriverObject
->DriverExtension
->AddDevice
= PNP_AddDevice
;
80 driver
->minidriver
= *registration
;
81 list_add_tail(&minidriver_list
, &driver
->entry
);
83 return STATUS_SUCCESS
;
86 static NTSTATUS WINAPI
internalComplete(DEVICE_OBJECT
*deviceObject
, IRP
*irp
,
89 SetEvent(irp
->UserEvent
);
90 return STATUS_MORE_PROCESSING_REQUIRED
;
93 NTSTATUS
call_minidriver(ULONG code
, DEVICE_OBJECT
*device
, void *in_buff
, ULONG in_size
, void *out_buff
, ULONG out_size
)
96 IO_STATUS_BLOCK irp_status
;
97 IO_STACK_LOCATION
*irpsp
;
101 HANDLE event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
105 buffer
= HeapAlloc(GetProcessHeap(), 0, out_size
);
106 memcpy(buffer
, out_buff
, out_size
);
109 irp
= IoBuildDeviceIoControlRequest(code
, device
, in_buff
, in_size
,
110 buffer
, out_size
, TRUE
, event
, &irp_status
);
112 irpsp
= IoGetNextIrpStackLocation(irp
);
113 irpsp
->CompletionRoutine
= internalComplete
;
114 irpsp
->Control
= SL_INVOKE_ON_SUCCESS
| SL_INVOKE_ON_ERROR
;
116 IoCallDriver(device
, irp
);
118 if (irp
->IoStatus
.u
.Status
== STATUS_PENDING
)
119 WaitForSingleObject(event
, INFINITE
);
121 memcpy(out_buff
, buffer
, out_size
);
122 status
= irp
->IoStatus
.u
.Status
;
124 IoCompleteRequest(irp
, IO_NO_INCREMENT
);