ReactOS  0.4.14-dev-376-gaedba84
usbhub.c File Reference
#include "usbhub.h"
#include <debug.h>
Include dependency graph for usbhub.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI USBHUB_Create (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI USBHUB_Close (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI USBHUB_Cleanup (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI USBHUB_AddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
 
static NTSTATUS NTAPI USBHUB_IrpStub (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI USBHUB_DispatchDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBHUB_DispatchSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBHUB_DispatchInternalDeviceControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBHUB_DispatchPnp (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI USBHUB_DispatchPower (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID NTAPI USBHUB_Unload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file usbhub.c.

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 277 of file usbhub.c.

280 {
283 
284  DPRINT("USBHUB: DriverEntry\n");
285 
294 
295  return STATUS_SUCCESS;
296 }
NTSTATUS NTAPI USBHUB_DispatchSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbhub.c:170
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
NTSTATUS NTAPI USBHUB_Close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:31
NTSTATUS NTAPI USBHUB_DispatchPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbhub.c:206
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
NTSTATUS NTAPI USBHUB_DispatchPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbhub.c:194
VOID NTAPI USBHUB_Unload(IN PDRIVER_OBJECT DriverObject)
Definition: usbhub.c:269
NTSTATUS NTAPI USBHUB_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:18
NTSTATUS NTAPI USBHUB_DispatchDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbhub.c:158
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI USBHUB_DispatchInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: usbhub.c:182
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
NTSTATUS NTAPI USBHUB_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: usbhub.c:58
#define IRP_MJ_SYSTEM_CONTROL
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS NTAPI USBHUB_Cleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:44
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

◆ USBHUB_AddDevice()

NTSTATUS NTAPI USBHUB_AddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 58 of file usbhub.c.

61 {
63  PHUB_DEVICE_EXTENSION HubDeviceExtension;
65  DPRINT("USBHUB: AddDevice (%p)\n", PhysicalDeviceObject);
66  //
67  // Create the Device Object
68  //
70  sizeof(HUB_DEVICE_EXTENSION),
71  NULL,
74  FALSE,
75  &DeviceObject);
76 
77  if (!NT_SUCCESS(Status))
78  {
79  DPRINT1("USBHUB: IoCreateDevice() failed with status 0x%08lx\n", Status);
80  return Status;
81  }
82 
83  //
84  // Zero Hub Extension
85  //
86  HubDeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
87  RtlZeroMemory(HubDeviceExtension, sizeof(HUB_DEVICE_EXTENSION));
88 
89  INITIALIZE_PNP_STATE(HubDeviceExtension->Common);
90 
91  //
92  // Set this to Fdo
93  //
94  HubDeviceExtension->Common.IsFDO = TRUE;
96 
97  // initialize mutex
98  KeInitializeGuardedMutex(&HubDeviceExtension->HubMutexLock);
99 
100  // initialize remove lock
101  IoInitializeRemoveLock(&HubDeviceExtension->Common.RemoveLock, 'buH', 0, 0);
102 
103  //
104  // initialize reset complete event
105  //
106  KeInitializeEvent(&HubDeviceExtension->ResetComplete, NotificationEvent, FALSE);
107 
108  //
109  // Attached to lower device
110  //
111  //Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
113  if (!NT_SUCCESS(Status))
114  {
115  DPRINT1("USBHUB: IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
117  return Status;
118  }
119 
122 
123  return STATUS_SUCCESS;
124 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
#define TRUE
Definition: types.h:120
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2785
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT LowerDeviceObject
Definition: usbhub.h:103
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
struct _HUB_DEVICE_EXTENSION * PHUB_DEVICE_EXTENSION
IO_REMOVE_LOCK RemoveLock
Definition: usbhub.h:78
KEVENT ResetComplete
Definition: usbhub.h:112
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
KGUARDED_MUTEX HubMutexLock
Definition: usbhub.h:109
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:102
#define DPRINT1
Definition: precomp.h:8
#define INITIALIZE_PNP_STATE(_Data_)
Definition: fbtusb.h:107
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:147

Referenced by DriverEntry().

◆ USBHUB_Cleanup()

NTSTATUS NTAPI USBHUB_Cleanup ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 44 of file usbhub.c.

47 {
48  DPRINT("USBHUB: IRP_MJ_CLEANUP\n");
49 
50  Irp->IoStatus.Status = STATUS_SUCCESS;
51  Irp->IoStatus.Information = 0;
53  return STATUS_SUCCESS;
54 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ USBHUB_Close()

NTSTATUS NTAPI USBHUB_Close ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 31 of file usbhub.c.

34 {
35  DPRINT("USBHUB: IRP_MJ_CLOSE\n");
36 
37  Irp->IoStatus.Status = STATUS_SUCCESS;
38  Irp->IoStatus.Information = 0;
40  return STATUS_SUCCESS;
41 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ USBHUB_Create()

NTSTATUS NTAPI USBHUB_Create ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 18 of file usbhub.c.

21 {
22  DPRINT("USBHUB: IRP_MJ_CREATE\n");
23 
24  Irp->IoStatus.Status = STATUS_SUCCESS;
25  Irp->IoStatus.Information = 0;
27  return STATUS_SUCCESS;
28 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ USBHUB_DispatchDeviceControl()

NTSTATUS NTAPI USBHUB_DispatchDeviceControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 158 of file usbhub.c.

161 {
162  DPRINT("Usbhub: DispatchDeviceControl\n");
163  if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Common.IsFDO)
165  else
167 }
_In_ PIRP Irp
Definition: csq.h:116
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
static NTSTATUS NTAPI USBHUB_IrpStub(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:127
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS USBHUB_FdoHandleDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:2280

Referenced by DriverEntry().

◆ USBHUB_DispatchInternalDeviceControl()

NTSTATUS NTAPI USBHUB_DispatchInternalDeviceControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 182 of file usbhub.c.

185 {
186  DPRINT("Usbhub: DispatchInternalDeviceControl\n");
187  if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Common.IsFDO)
189  else
191 }
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS USBHUB_PdoHandleInternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:175
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
static NTSTATUS NTAPI USBHUB_IrpStub(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:127
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by DriverEntry().

◆ USBHUB_DispatchPnp()

NTSTATUS NTAPI USBHUB_DispatchPnp ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 194 of file usbhub.c.

197 {
198  DPRINT("USBHUB: DispatchPnp\n");
199  if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Common.IsFDO)
201  else
203 }
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS USBHUB_PdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:583
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS USBHUB_FdoHandlePnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:2029
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by DriverEntry().

◆ USBHUB_DispatchPower()

NTSTATUS NTAPI USBHUB_DispatchPower ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 206 of file usbhub.c.

209 {
210  PIO_STACK_LOCATION IoStack;
211  PHUB_DEVICE_EXTENSION DeviceExtension;
214  DeviceExtension = DeviceObject->DeviceExtension;
215 
216  Status = IoAcquireRemoveLock(&DeviceExtension->Common.RemoveLock, Irp);
217  if (!NT_SUCCESS(Status))
218  {
219  Irp->IoStatus.Status = Status;
221  return Status;
222  }
223 
224  DPRINT1("Power Function %x\n", IoStack->MinorFunction);
225 
226  if (DeviceExtension->Common.IsFDO)
227  {
230  Status = PoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
231  IoReleaseRemoveLock(&DeviceExtension->Common.RemoveLock, Irp);
232  return Status;
233  }
234 
235  switch (IoStack->MinorFunction)
236  {
237  case IRP_MN_SET_POWER:
238  {
239  DPRINT("IRP_MN_SET_POWER\n");
240  break;
241  }
242  case IRP_MN_QUERY_POWER:
243  {
244  DPRINT("IRP_MN_QUERY_POWER\n");
245  break;
246  }
247  case IRP_MN_WAIT_WAKE:
248  {
249  DPRINT("IRP_MN_WAIT_WAKE\n");
250  break;
251  }
252  default:
253  {
254  DPRINT1("PDO IRP_MJ_POWER / unknown minor function 0x%lx\n", IoStack->MinorFunction);
256  return Irp->IoStatus.Status;
257  }
258  }
259 
261  Irp->IoStatus.Status = STATUS_SUCCESS;
263  IoReleaseRemoveLock(&DeviceExtension->Common.RemoveLock, Irp);
264  return STATUS_SUCCESS;
265 }
#define IRP_MN_QUERY_POWER
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2716
PDEVICE_OBJECT LowerDeviceObject
Definition: usbhub.h:103
IO_REMOVE_LOCK RemoveLock
Definition: usbhub.h:78
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_SET_POWER
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
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:102
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define IRP_MN_WAIT_WAKE
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define IoAcquireRemoveLock(RemoveLock, Tag)

Referenced by DriverEntry().

◆ USBHUB_DispatchSystemControl()

NTSTATUS NTAPI USBHUB_DispatchSystemControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 170 of file usbhub.c.

173 {
174  DPRINT("Usbhub: DispatchSystemControl\n");
175  if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Common.IsFDO)
177  else
179 }
_In_ PIRP Irp
Definition: csq.h:116
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
static NTSTATUS NTAPI USBHUB_IrpStub(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:127
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by DriverEntry().

◆ USBHUB_IrpStub()

static NTSTATUS NTAPI USBHUB_IrpStub ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 127 of file usbhub.c.

130 {
132 
133  if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Common.IsFDO)
134  {
135  DPRINT1("Usbhub: FDO stub for major function 0x%lx\n",
136  IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
138  }
139  else
140  {
141  //
142  // Cant forward as we are the PDO!
143  //
144  DPRINT1("USBHUB: ERROR- PDO stub for major function 0x%lx\n",
145  IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
146 #ifndef NDEBUG
147  DbgBreakPoint();
148 #endif
149  }
150 
151  Status = Irp->IoStatus.Status;
153  return Status;
154 }
_In_ PIRP Irp
Definition: csq.h:116
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
LONG NTSTATUS
Definition: precomp.h:26
void DbgBreakPoint()
Definition: mach.c:553
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
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:566

Referenced by USBHUB_DispatchDeviceControl(), USBHUB_DispatchInternalDeviceControl(), and USBHUB_DispatchSystemControl().

◆ USBHUB_Unload()

VOID NTAPI USBHUB_Unload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 269 of file usbhub.c.

271 {
273 }
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by DriverEntry().