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 list_remove(&md
->entry
);
55 HeapFree( GetProcessHeap(), 0, md
);
59 NTSTATUS WINAPI
HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION
*registration
)
62 driver
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*driver
));
65 return STATUS_NO_MEMORY
;
67 driver
->DriverUnload
= registration
->DriverObject
->DriverUnload
;
68 registration
->DriverObject
->DriverUnload
= UnloadDriver
;
70 registration
->DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = HID_Device_ioctl
;
71 registration
->DriverObject
->MajorFunction
[IRP_MJ_READ
] = HID_Device_read
;
72 registration
->DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = HID_Device_write
;
73 registration
->DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = HID_Device_create
;
74 registration
->DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = HID_Device_close
;
76 driver
->PNPDispatch
= registration
->DriverObject
->MajorFunction
[IRP_MJ_PNP
];
77 registration
->DriverObject
->MajorFunction
[IRP_MJ_PNP
] = HID_PNP_Dispatch
;
79 driver
->AddDevice
= registration
->DriverObject
->DriverExtension
->AddDevice
;
80 registration
->DriverObject
->DriverExtension
->AddDevice
= PNP_AddDevice
;
82 driver
->minidriver
= *registration
;
83 list_add_tail(&minidriver_list
, &driver
->entry
);
85 return STATUS_SUCCESS
;
88 static NTSTATUS WINAPI
internalComplete(DEVICE_OBJECT
*deviceObject
, IRP
*irp
,
91 HANDLE event
= context
;
93 return STATUS_MORE_PROCESSING_REQUIRED
;
96 NTSTATUS
call_minidriver(ULONG code
, DEVICE_OBJECT
*device
, void *in_buff
, ULONG in_size
, void *out_buff
, ULONG out_size
)
99 IO_STATUS_BLOCK irp_status
;
101 HANDLE event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
103 irp
= IoBuildDeviceIoControlRequest(code
, device
, in_buff
, in_size
,
104 out_buff
, out_size
, TRUE
, NULL
, &irp_status
);
106 IoSetCompletionRoutine(irp
, internalComplete
, event
, TRUE
, TRUE
, TRUE
);
107 status
= IoCallDriver(device
, irp
);
109 if (status
== STATUS_PENDING
)
110 WaitForSingleObject(event
, INFINITE
);
112 status
= irp
->IoStatus
.u
.Status
;
114 IoCompleteRequest(irp
, IO_NO_INCREMENT
);