Commit e30a1452 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

hidclass.sys: Merge main.c into pnp.c.

parent 5cc9c5ab
......@@ -9,5 +9,4 @@ C_SRCS = \
buffer.c \
descriptor.c \
device.c \
main.c \
pnp.c
......@@ -86,7 +86,6 @@ typedef struct _minidriver
} minidriver;
NTSTATUS call_minidriver(ULONG code, DEVICE_OBJECT *device, void *in_buff, ULONG in_size, void *out_buff, ULONG out_size) DECLSPEC_HIDDEN;
minidriver* find_minidriver(DRIVER_OBJECT* driver) DECLSPEC_HIDDEN;
/* Internal device functions */
NTSTATUS HID_CreateDevice(DEVICE_OBJECT *native_device, HID_MINIDRIVER_REGISTRATION *driver, DEVICE_OBJECT **device) DECLSPEC_HIDDEN;
......@@ -99,10 +98,6 @@ NTSTATUS WINAPI HID_Device_read(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN
NTSTATUS WINAPI HID_Device_write(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN;
NTSTATUS WINAPI HID_Device_create(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN;
NTSTATUS WINAPI HID_Device_close(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN;
NTSTATUS WINAPI HID_PNP_Dispatch(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN;
/* Pseudo-Plug and Play support*/
NTSTATUS WINAPI PNP_AddDevice(DRIVER_OBJECT *driver, DEVICE_OBJECT* PDO) DECLSPEC_HIDDEN;
/* Parsing HID Report Descriptors into preparsed data */
WINE_HIDP_PREPARSED_DATA* ParseDescriptor(BYTE *descriptor, unsigned int length) DECLSPEC_HIDDEN;
/*
* WINE Hid device services
*
* Copyright 2015 Aric Stewart
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define NONAMELESSUNION
#include <unistd.h>
#include <stdarg.h>
#include "hid.h"
#include "wine/debug.h"
#include "wine/list.h"
WINE_DEFAULT_DEBUG_CHANNEL(hid);
static struct list minidriver_list = LIST_INIT(minidriver_list);
minidriver* find_minidriver(DRIVER_OBJECT *driver)
{
minidriver *md;
LIST_FOR_EACH_ENTRY(md, &minidriver_list, minidriver, entry)
{
if (md->minidriver.DriverObject == driver)
return md;
}
return NULL;
}
static VOID WINAPI UnloadDriver(DRIVER_OBJECT *driver)
{
minidriver *md;
TRACE("Driver Unload\n");
md = find_minidriver(driver);
if (md)
{
if (md->DriverUnload)
md->DriverUnload(md->minidriver.DriverObject);
list_remove(&md->entry);
HeapFree( GetProcessHeap(), 0, md );
}
}
NTSTATUS WINAPI HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION *registration)
{
minidriver *driver;
driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*driver));
if (!driver)
return STATUS_NO_MEMORY;
driver->DriverUnload = registration->DriverObject->DriverUnload;
registration->DriverObject->DriverUnload = UnloadDriver;
registration->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HID_Device_ioctl;
registration->DriverObject->MajorFunction[IRP_MJ_READ] = HID_Device_read;
registration->DriverObject->MajorFunction[IRP_MJ_WRITE] = HID_Device_write;
registration->DriverObject->MajorFunction[IRP_MJ_CREATE] = HID_Device_create;
registration->DriverObject->MajorFunction[IRP_MJ_CLOSE] = HID_Device_close;
driver->PNPDispatch = registration->DriverObject->MajorFunction[IRP_MJ_PNP];
registration->DriverObject->MajorFunction[IRP_MJ_PNP] = HID_PNP_Dispatch;
driver->AddDevice = registration->DriverObject->DriverExtension->AddDevice;
registration->DriverObject->DriverExtension->AddDevice = PNP_AddDevice;
driver->minidriver = *registration;
list_add_tail(&minidriver_list, &driver->entry);
return STATUS_SUCCESS;
}
NTSTATUS call_minidriver(ULONG code, DEVICE_OBJECT *device, void *in_buff, ULONG in_size, void *out_buff, ULONG out_size)
{
IRP *irp;
IO_STATUS_BLOCK io;
KEVENT event;
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildDeviceIoControlRequest(code, device, in_buff, in_size,
out_buff, out_size, TRUE, &event, &io);
if (IoCallDriver(device, irp) == STATUS_PENDING)
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
return io.u.Status;
}
/*
* WINE HID Pseudo-Plug and Play support
* Human Interface Device class driver
*
* Copyright 2015 Aric Stewart
*
......@@ -30,6 +30,19 @@
WINE_DEFAULT_DEBUG_CHANNEL(hid);
static struct list minidriver_list = LIST_INIT(minidriver_list);
static minidriver *find_minidriver(DRIVER_OBJECT *driver)
{
minidriver *md;
LIST_FOR_EACH_ENTRY(md, &minidriver_list, minidriver, entry)
{
if (md->minidriver.DriverObject == driver)
return md;
}
return NULL;
}
static NTSTATUS WINAPI internalComplete(DEVICE_OBJECT *deviceObject, IRP *irp,
void *context)
{
......@@ -69,7 +82,7 @@ static NTSTATUS get_device_id(DEVICE_OBJECT *device, BUS_QUERY_ID_TYPE type, WCH
return status;
}
NTSTATUS WINAPI PNP_AddDevice(DRIVER_OBJECT *driver, DEVICE_OBJECT *PDO)
static NTSTATUS WINAPI driver_add_device(DRIVER_OBJECT *driver, DEVICE_OBJECT *PDO)
{
WCHAR device_id[MAX_DEVICE_ID_LEN], instance_id[MAX_DEVICE_ID_LEN];
DEVICE_OBJECT *device = NULL;
......@@ -211,7 +224,7 @@ static NTSTATUS remove_device(minidriver *minidriver, DEVICE_OBJECT *device, IRP
return rc;
}
NTSTATUS WINAPI HID_PNP_Dispatch(DEVICE_OBJECT *device, IRP *irp)
static NTSTATUS WINAPI driver_pnp(DEVICE_OBJECT *device, IRP *irp)
{
NTSTATUS rc = STATUS_NOT_SUPPORTED;
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
......@@ -296,3 +309,63 @@ NTSTATUS WINAPI HID_PNP_Dispatch(DEVICE_OBJECT *device, IRP *irp)
IoCompleteRequest( irp, IO_NO_INCREMENT );
return rc;
}
static void WINAPI driver_unload(DRIVER_OBJECT *driver)
{
minidriver *md;
TRACE("\n");
if ((md = find_minidriver(driver)))
{
if (md->DriverUnload)
md->DriverUnload(md->minidriver.DriverObject);
list_remove(&md->entry);
HeapFree(GetProcessHeap(), 0, md);
}
}
NTSTATUS WINAPI HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION *registration)
{
minidriver *driver;
if (!(driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*driver))))
return STATUS_NO_MEMORY;
driver->DriverUnload = registration->DriverObject->DriverUnload;
registration->DriverObject->DriverUnload = driver_unload;
registration->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HID_Device_ioctl;
registration->DriverObject->MajorFunction[IRP_MJ_READ] = HID_Device_read;
registration->DriverObject->MajorFunction[IRP_MJ_WRITE] = HID_Device_write;
registration->DriverObject->MajorFunction[IRP_MJ_CREATE] = HID_Device_create;
registration->DriverObject->MajorFunction[IRP_MJ_CLOSE] = HID_Device_close;
driver->PNPDispatch = registration->DriverObject->MajorFunction[IRP_MJ_PNP];
registration->DriverObject->MajorFunction[IRP_MJ_PNP] = driver_pnp;
driver->AddDevice = registration->DriverObject->DriverExtension->AddDevice;
registration->DriverObject->DriverExtension->AddDevice = driver_add_device;
driver->minidriver = *registration;
list_add_tail(&minidriver_list, &driver->entry);
return STATUS_SUCCESS;
}
NTSTATUS call_minidriver(ULONG code, DEVICE_OBJECT *device, void *in_buff, ULONG in_size, void *out_buff, ULONG out_size)
{
IRP *irp;
IO_STATUS_BLOCK io;
KEVENT event;
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildDeviceIoControlRequest(code, device, in_buff, in_size,
out_buff, out_size, TRUE, &event, &io);
if (IoCallDriver(device, irp) == STATUS_PENDING)
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
return io.u.Status;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment