Create the AHCI branch for Aman's work
[reactos.git] / sdk / 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 #include "libusb.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 //
17 // driver verifier
18 //
19 DRIVER_ADD_DEVICE USBLIB_AddDevice;
20
21 extern
22 "C"
23 {
24 NTSTATUS
25 NTAPI
26 USBLIB_AddDevice(
27 PDRIVER_OBJECT DriverObject,
28 PDEVICE_OBJECT PhysicalDeviceObject)
29 {
30 NTSTATUS Status;
31 PHCDCONTROLLER HcdController;
32
33 DPRINT("USBLIB_AddDevice\n");
34
35 /* first create the controller object */
36 Status = CreateHCDController(&HcdController);
37 if (!NT_SUCCESS(Status))
38 {
39 /* failed to create hcd */
40 DPRINT1("AddDevice: Failed to create hcd with %x\n", Status);
41 return Status;
42 }
43
44 /* initialize the hcd */
45 Status = HcdController->Initialize(NULL, // FIXME
46 DriverObject,
47 PhysicalDeviceObject);
48
49 /* check for success */
50 if (!NT_SUCCESS(Status))
51 {
52 /* failed to initialize device */
53 DPRINT1("AddDevice: failed to initialize\n");
54
55 /* release object */
56 HcdController->Release();
57 }
58
59 return Status;
60
61 }
62 }
63
64 extern
65 "C"
66 {
67 NTSTATUS
68 NTAPI
69 USBLIB_Dispatch(
70 PDEVICE_OBJECT DeviceObject,
71 PIRP Irp)
72 {
73 PCOMMON_DEVICE_EXTENSION DeviceExtension;
74 PIO_STACK_LOCATION IoStack;
75 NTSTATUS Status;
76
77 //
78 // get common device extension
79 //
80 DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
81
82 //
83 // get current stack location
84 //
85 IoStack = IoGetCurrentIrpStackLocation(Irp);
86
87 //
88 // sanity checks
89 //
90 PC_ASSERT(DeviceExtension->Dispatcher);
91
92 switch(IoStack->MajorFunction)
93 {
94 case IRP_MJ_PNP:
95 {
96 //
97 // dispatch pnp
98 //
99 return DeviceExtension->Dispatcher->HandlePnp(DeviceObject, Irp);
100 }
101
102 case IRP_MJ_POWER:
103 {
104 //
105 // dispatch power
106 //
107 return DeviceExtension->Dispatcher->HandlePower(DeviceObject, Irp);
108 }
109 case IRP_MJ_INTERNAL_DEVICE_CONTROL:
110 case IRP_MJ_DEVICE_CONTROL:
111 {
112 //
113 // dispatch io control
114 //
115 return DeviceExtension->Dispatcher->HandleDeviceControl(DeviceObject, Irp);
116 }
117 case IRP_MJ_SYSTEM_CONTROL:
118 {
119 //
120 // dispatch system control
121 //
122 return DeviceExtension->Dispatcher->HandleSystemControl(DeviceObject, Irp);
123 }
124 default:
125 {
126 DPRINT1("USBLIB_Dispatch> Major %lu Minor %lu unhandeled\n", IoStack->MajorFunction, IoStack->MinorFunction);
127 Status = STATUS_SUCCESS;
128 }
129 }
130
131 //
132 // complete request
133 //
134 Irp->IoStatus.Information = 0;
135 Irp->IoStatus.Status = Status;
136 IoCompleteRequest(Irp, IO_NO_INCREMENT);
137
138 return Status;
139 }
140 }