ReactOS  0.4.13-dev-257-gfabbd7c
libusb.h File Reference
#include <ntddk.h>
#include <hubbusif.h>
#include <usbbusif.h>
#include <usbdlib.h>
#include <stdio.h>
#include <wdmguid.h>
#include <portcls.h>
#include <kcom.h>
#include "common_interfaces.h"
Include dependency graph for libusb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  COMMON_DEVICE_EXTENSION
 
struct  _WORK_ITEM_DATA
 

Macros

#define _NEW_DELETE_OPERATORS_
 
#define PORT_ENABLE   1
 
#define PORT_SUSPEND   2
 
#define PORT_OVER_CURRENT   3
 
#define PORT_RESET   4
 
#define PORT_POWER   8
 
#define C_PORT_CONNECTION   16
 
#define C_PORT_ENABLE   17
 
#define C_PORT_SUSPEND   18
 
#define C_PORT_OVER_CURRENT   19
 
#define C_PORT_RESET   20
 
#define TAG_USBLIB   'LBSU'
 
#define PC_ASSERT(exp)
 

Typedefs

typedef struct COMMON_DEVICE_EXTENSIONPCOMMON_DEVICE_EXTENSION
 
typedef struct _WORK_ITEM_DATA INIT_ROOT_HUB_CONTEXT
 
typedef struct _WORK_ITEM_DATAPINIT_ROOT_HUB_CONTEXT
 

Functions

PVOID __cdecl operator new (size_t iSize, POOL_TYPE poolType, ULONG tag)
 
NTSTATUS NTAPI CreateHCDController (PHCDCONTROLLER *HcdController)
 
NTSTATUS NTAPI CreateUSBHardware (PUSBHARDWAREDEVICE *OutHardware)
 
NTSTATUS NTAPI SyncForwardIrp (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI GetBusInterface (PDEVICE_OBJECT DeviceObject, PBUS_INTERFACE_STANDARD busInterface)
 
NTSTATUS NTAPI CreateHubController (PHUBCONTROLLER *OutHubController)
 
NTSTATUS NTAPI CreateDMAMemoryManager (PDMAMEMORYMANAGER *OutMemoryManager)
 
NTSTATUS NTAPI CreateUSBDevice (PUSBDEVICE *OutDevice)
 
NTSTATUS NTAPI USBLIB_AddDevice (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
 
NTSTATUS NTAPI USBLIB_Dispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 

Macro Definition Documentation

◆ _NEW_DELETE_OPERATORS_

#define _NEW_DELETE_OPERATORS_

Definition at line 25 of file libusb.h.

◆ C_PORT_CONNECTION

#define C_PORT_CONNECTION   16

Definition at line 46 of file libusb.h.

◆ C_PORT_ENABLE

#define C_PORT_ENABLE   17

Definition at line 47 of file libusb.h.

◆ C_PORT_OVER_CURRENT

#define C_PORT_OVER_CURRENT   19

Definition at line 49 of file libusb.h.

◆ C_PORT_RESET

#define C_PORT_RESET   20

Definition at line 50 of file libusb.h.

◆ C_PORT_SUSPEND

#define C_PORT_SUSPEND   18

Definition at line 48 of file libusb.h.

◆ PC_ASSERT

#define PC_ASSERT (   exp)
Value:
(VOID)((!(exp)) ? \
RtlAssert((PVOID) #exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
#define VOID
Definition: acefi.h:82
DWORD exp
Definition: msg.c:15681

Definition at line 75 of file libusb.h.

◆ PORT_ENABLE

#define PORT_ENABLE   1

Definition at line 41 of file libusb.h.

◆ PORT_OVER_CURRENT

#define PORT_OVER_CURRENT   3

Definition at line 43 of file libusb.h.

◆ PORT_POWER

#define PORT_POWER   8

Definition at line 45 of file libusb.h.

◆ PORT_RESET

#define PORT_RESET   4

Definition at line 44 of file libusb.h.

◆ PORT_SUSPEND

#define PORT_SUSPEND   2

Definition at line 42 of file libusb.h.

◆ TAG_USBLIB

#define TAG_USBLIB   'LBSU'

Definition at line 70 of file libusb.h.

Typedef Documentation

◆ INIT_ROOT_HUB_CONTEXT

◆ PCOMMON_DEVICE_EXTENSION

◆ PINIT_ROOT_HUB_CONTEXT

Function Documentation

◆ CreateDMAMemoryManager()

NTSTATUS NTAPI CreateDMAMemoryManager ( PDMAMEMORYMANAGER OutMemoryManager)

Definition at line 340 of file memory_manager.cpp.

342 {
344 
345  //
346  // allocate controller
347  //
349  if (!This)
350  {
351  //
352  // failed to allocate
353  //
355  }
356 
357  //
358  // add reference count
359  //
360  This->AddRef();
361 
362  //
363  // return result
364  //
365  *OutMemoryManager = (PDMAMEMORYMANAGER)This;
366 
367  //
368  // done
369  //
370  return STATUS_SUCCESS;
371 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_USBLIB
Definition: libusb.h:70
IDMAMemoryManager * PDMAMEMORYMANAGER
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ CreateHCDController()

NTSTATUS NTAPI CreateHCDController ( PHCDCONTROLLER HcdController)

Definition at line 760 of file hcd_controller.cpp.

762 {
764 
765  //
766  // allocate controller
767  //
769  if (!This)
770  {
771  //
772  // failed to allocate
773  //
775  }
776 
777  //
778  // add reference count
779  //
780  This->AddRef();
781 
782  //
783  // return result
784  //
785  *OutHcdController = (PHCDCONTROLLER)This;
786 
787  //
788  // done
789  //
790  return STATUS_SUCCESS;
791 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_USBLIB
Definition: libusb.h:70
return STATUS_SUCCESS
Definition: btrfs.c:2745
IHCDController * PHCDCONTROLLER

Referenced by USBLIB_AddDevice().

◆ CreateHubController()

NTSTATUS NTAPI CreateHubController ( PHUBCONTROLLER OutHubController)

Definition at line 3959 of file hub_controller.cpp.

3961 {
3963 
3964  //
3965  // allocate controller
3966  //
3968  if (!This)
3969  {
3970  //
3971  // failed to allocate
3972  //
3974  }
3975 
3976  //
3977  // add reference count
3978  //
3979  This->AddRef();
3980 
3981  //
3982  // return result
3983  //
3984  *OutHcdController = (PHUBCONTROLLER)This;
3985 
3986  //
3987  // done
3988  //
3989  return STATUS_SUCCESS;
3990 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_USBLIB
Definition: libusb.h:70
IHubController * PHUBCONTROLLER
return STATUS_SUCCESS
Definition: btrfs.c:2745

Referenced by CHCDController::HandlePnp().

◆ CreateUSBDevice()

NTSTATUS NTAPI CreateUSBDevice ( PUSBDEVICE OutDevice)

Definition at line 1297 of file usb_device.cpp.

1299 {
1300  CUSBDevice * This;
1301 
1302  //
1303  // allocate controller
1304  //
1306  if (!This)
1307  {
1308  //
1309  // failed to allocate
1310  //
1312  }
1313 
1314  //
1315  // add reference count
1316  //
1317  This->AddRef();
1318 
1319  //
1320  // return result
1321  //
1322  *OutDevice = (PUSBDEVICE)This;
1323 
1324  //
1325  // done
1326  //
1327  return STATUS_SUCCESS;
1328 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IUSBDevice * PUSBDEVICE
#define TAG_USBLIB
Definition: libusb.h:70
return STATUS_SUCCESS
Definition: btrfs.c:2745

Referenced by USBHI_CreateUsbDevice().

◆ CreateUSBHardware()

NTSTATUS NTAPI CreateUSBHardware ( PUSBHARDWAREDEVICE OutHardware)

Definition at line 1474 of file hardware.cpp.

1476 {
1478 
1480 
1481  if (!This)
1483 
1484  This->AddRef();
1485 
1486  // return result
1487  *OutHardware = (PUSBHARDWAREDEVICE)This;
1488 
1489  return STATUS_SUCCESS;
1490 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IUSBHardwareDevice * PUSBHARDWAREDEVICE
#define TAG_USBEHCI
Definition: usbehci.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2745

Referenced by CHCDController::Initialize().

◆ GetBusInterface()

NTSTATUS NTAPI GetBusInterface ( PDEVICE_OBJECT  DeviceObject,
PBUS_INTERFACE_STANDARD  busInterface 
)

Definition at line 88 of file misc.cpp.

91 {
92  KEVENT Event;
94  PIRP Irp;
96  PIO_STACK_LOCATION Stack;
97 
98  if ((!DeviceObject) || (!busInterface))
99  return STATUS_UNSUCCESSFUL;
100 
102 
104  DeviceObject,
105  NULL,
106  0,
107  NULL,
108  &Event,
109  &IoStatus);
110 
111  if (Irp == NULL)
112  {
114  }
115 
117  Stack->MajorFunction = IRP_MJ_PNP;
119  Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
120  Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_BUS_INTERFACE_STANDARD;
121  Stack->Parameters.QueryInterface.Version = 1;
122  Stack->Parameters.QueryInterface.Interface = (PINTERFACE)busInterface;
123  Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
124  Irp->IoStatus.Status=STATUS_NOT_SUPPORTED ;
125 
127 
128  if (Status == STATUS_PENDING)
129  {
131 
132  Status=IoStatus.Status;
133  }
134 
135  return Status;
136 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
struct _INTERFACE * PINTERFACE
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_QUERY_INTERFACE
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct _BUS_INTERFACE_STANDARD BUS_INTERFACE_STANDARD
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
GUID * LPGUID
Definition: guiddef.h:76

◆ operator new()

PVOID __cdecl operator new ( size_t  iSize,
POOL_TYPE  poolType,
ULONG  tag 
)

Definition at line 23 of file libusb.cpp.

27 {
28  PVOID result = ExAllocatePoolWithTag(poolType, iSize, tag);
29  if (result) {
30  RtlZeroMemory(result, iSize);
31  }
32  return result;
33 }
Definition: ecma_167.h:138
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
GLuint64EXT * result
Definition: glext.h:11304

◆ SyncForwardIrp()

NTSTATUS NTAPI SyncForwardIrp ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 37 of file misc.cpp.

38 {
39  KEVENT Event;
41 
42  //
43  // initialize event
44  //
46 
47  //
48  // copy irp stack location
49  //
51 
52  //
53  // set completion routine
54  //
56 
57 
58  //
59  // call driver
60  //
62 
63 
64  //
65  // check if pending
66  //
67  if (Status == STATUS_PENDING)
68  {
69  //
70  // wait for the request to finish
71  //
73 
74  //
75  // copy status code
76  //
77  Status = Irp->IoStatus.Status;
78  }
79 
80  //
81  // done
82  //
83  return Status;
84 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine
Definition: misc.cpp:19
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218

Referenced by CHCDController::HandlePnp().

◆ USBLIB_AddDevice()

NTSTATUS NTAPI USBLIB_AddDevice ( PDRIVER_OBJECT  DriverObject,
PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 56 of file libusb.cpp.

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 }
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI CreateHCDController(PHCDCONTROLLER *OutHcdController)
IHCDController * PHCDCONTROLLER

◆ USBLIB_Dispatch()

NTSTATUS NTAPI USBLIB_Dispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 99 of file libusb.cpp.

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 }
#define PC_ASSERT(exp)
Definition: usbehci.h:17
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#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
#define IO_NO_INCREMENT
Definition: iotypes.h:565
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Referenced by DriverEntry().