Synchronize with trunk revision 59781.
[reactos.git] / lib / drivers / libusb / libusb.cpp
1 /*
2 * PROJECT: ReactOS Universal Serial Bus Bulk Driver Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/drivers/libusb/libusb.cpp
5 * PURPOSE: USB Common Driver Library.
6 * PROGRAMMERS:
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
9 */
10
11
12 #include "libusb.h"
13
14 //
15 // driver verifier
16 //
17 DRIVER_ADD_DEVICE USBLIB_AddDevice;
18
19 extern
20 "C"
21 {
22 NTSTATUS
23 NTAPI
24 USBLIB_AddDevice(
25 PDRIVER_OBJECT DriverObject,
26 PDEVICE_OBJECT PhysicalDeviceObject)
27 {
28 NTSTATUS Status;
29 PHCDCONTROLLER HcdController;
30
31 DPRINT1("USBLIB_AddDevice\n");
32
33 /* first create the controller object */
34 Status = CreateHCDController(&HcdController);
35 if (!NT_SUCCESS(Status))
36 {
37 /* failed to create hcd */
38 DPRINT1("AddDevice: Failed to create hcd with %x\n", Status);
39 return Status;
40 }
41
42 /* initialize the hcd */
43 Status = HcdController->Initialize(NULL, // FIXME
44 DriverObject,
45 PhysicalDeviceObject);
46
47 /* check for success */
48 if (!NT_SUCCESS(Status))
49 {
50 /* failed to initialize device */
51 DPRINT1("AddDevice: failed to initialize\n");
52
53 /* release object */
54 HcdController->Release();
55 }
56
57 return Status;
58
59 }
60 }
61
62 extern
63 "C"
64 {
65 NTSTATUS
66 NTAPI
67 USBLIB_Dispatch(
68 PDEVICE_OBJECT DeviceObject,
69 PIRP Irp)
70 {
71 PCOMMON_DEVICE_EXTENSION DeviceExtension;
72 PIO_STACK_LOCATION IoStack;
73 NTSTATUS Status;
74
75 //
76 // get common device extension
77 //
78 DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
79
80 //
81 // get current stack location
82 //
83 IoStack = IoGetCurrentIrpStackLocation(Irp);
84
85 //
86 // sanity checks
87 //
88 PC_ASSERT(DeviceExtension->Dispatcher);
89
90 switch(IoStack->MajorFunction)
91 {
92 case IRP_MJ_PNP:
93 {
94 //
95 // dispatch pnp
96 //
97 return DeviceExtension->Dispatcher->HandlePnp(DeviceObject, Irp);
98 }
99
100 case IRP_MJ_POWER:
101 {
102 //
103 // dispatch pnp
104 //
105 return DeviceExtension->Dispatcher->HandlePower(DeviceObject, Irp);
106 }
107 case IRP_MJ_INTERNAL_DEVICE_CONTROL:
108 case IRP_MJ_DEVICE_CONTROL:
109 {
110 //
111 // dispatch pnp
112 //
113 return DeviceExtension->Dispatcher->HandleDeviceControl(DeviceObject, Irp);
114 }
115 default:
116 {
117 DPRINT1("USBLIB_Dispatch> Major %lu Minor %lu unhandeled\n", IoStack->MajorFunction, IoStack->MinorFunction);
118 Status = STATUS_SUCCESS;
119 }
120 }
121
122 //
123 // complete request
124 //
125 Irp->IoStatus.Information = 0;
126 Irp->IoStatus.Status = Status;
127 IoCompleteRequest(Irp, IO_NO_INCREMENT);
128
129 return Status;
130 }
131 }