ReactOS  0.4.14-dev-342-gdc047f9
libusb.cpp
Go to the documentation of this file.
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 PVOID
22 __cdecl
23 operator new(
24  size_t iSize,
25  POOL_TYPE poolType,
26  ULONG tag)
27 {
28  PVOID result = ExAllocatePoolWithTag(poolType, iSize, tag);
29  if (result) {
30  RtlZeroMemory(result, iSize);
31  }
32  return result;
33 }
34 
35 void
36 __cdecl
37 operator delete(
38  PVOID pVoid)
39 {
40  if (pVoid) ExFreePool(pVoid);
41 }
42 
43 void
44 __cdecl
45 operator delete(
46  PVOID pVoid, UINT_PTR)
47 {
48  if (pVoid) ExFreePool(pVoid);
49 }
50 
51 extern
52 "C"
53 {
55 NTAPI
59 {
61  PHCDCONTROLLER HcdController;
62 
63  DPRINT("USBLIB_AddDevice\n");
64 
65  /* first create the controller object */
66  Status = CreateHCDController(&HcdController);
67  if (!NT_SUCCESS(Status))
68  {
69  /* failed to create hcd */
70  DPRINT1("AddDevice: Failed to create hcd with %x\n", Status);
71  return Status;
72  }
73 
74  /* initialize the hcd */
75  Status = HcdController->Initialize(NULL, // FIXME
78 
79  /* check for success */
80  if (!NT_SUCCESS(Status))
81  {
82  /* failed to initialize device */
83  DPRINT1("AddDevice: failed to initialize\n");
84 
85  /* release object */
86  HcdController->Release();
87  }
88 
89  return Status;
90 
91 }
92 }
93 
94 extern
95 "C"
96 {
98 NTAPI
101  PIRP Irp)
102 {
103  PCOMMON_DEVICE_EXTENSION DeviceExtension;
104  PIO_STACK_LOCATION IoStack;
106 
107  //
108  // get common device extension
109  //
111 
112  //
113  // get current stack location
114  //
116 
117  //
118  // sanity checks
119  //
120  PC_ASSERT(DeviceExtension->Dispatcher);
121 
122  switch(IoStack->MajorFunction)
123  {
124  case IRP_MJ_PNP:
125  {
126  //
127  // dispatch pnp
128  //
129  return DeviceExtension->Dispatcher->HandlePnp(DeviceObject, Irp);
130  }
131 
132  case IRP_MJ_POWER:
133  {
134  //
135  // dispatch power
136  //
137  return DeviceExtension->Dispatcher->HandlePower(DeviceObject, Irp);
138  }
141  {
142  //
143  // dispatch io control
144  //
145  return DeviceExtension->Dispatcher->HandleDeviceControl(DeviceObject, Irp);
146  }
148  {
149  //
150  // dispatch system control
151  //
152  return DeviceExtension->Dispatcher->HandleSystemControl(DeviceObject, Irp);
153  }
154  default:
155  {
156  DPRINT1("USBLIB_Dispatch> Major %lu Minor %lu unhandeled\n", IoStack->MajorFunction, IoStack->MinorFunction);
158  }
159  }
160 
161  //
162  // complete request
163  //
164  Irp->IoStatus.Information = 0;
165  Irp->IoStatus.Status = Status;
167 
168  return Status;
169 }
170 }
unsigned __int3264 UINT_PTR
Definition: activex.cpp:275
#define PC_ASSERT(exp)
Definition: usbehci.h:17
#define __cdecl
Definition: accygwin.h:79
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
Definition: ecma_167.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
DRIVER_ADD_DEVICE USBLIB_AddDevice
Definition: libusb.cpp:19
NTSTATUS NTAPI USBLIB_Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: libusb.cpp:99
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:76
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IRP_MJ_POWER
#define IRP_MJ_SYSTEM_CONTROL
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI CreateHCDController(PHCDCONTROLLER *OutHcdController)
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938
GLuint64EXT * result
Definition: glext.h:11304
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
char * tag
Definition: main.c:59
IHCDController * PHCDCONTROLLER