2014-02-06 11:18:34 +00:00
|
|
|
#ifndef _USBHUB_H_
|
|
|
|
#define _USBHUB_H_
|
2011-05-04 01:07:21 +00:00
|
|
|
|
2014-02-03 10:53:08 +00:00
|
|
|
#include <wdm.h>
|
2011-05-04 01:07:21 +00:00
|
|
|
#include <hubbusif.h>
|
|
|
|
#include <usbbusif.h>
|
|
|
|
#include <usbdlib.h>
|
2013-12-21 19:15:13 +00:00
|
|
|
|
2011-05-04 01:07:21 +00:00
|
|
|
#define USB_HUB_TAG 'hbsu'
|
|
|
|
#define USB_MAXCHILDREN 127
|
|
|
|
|
|
|
|
// Lifted from broken header above
|
|
|
|
#define C_HUB_LOCAL_POWER 0
|
|
|
|
#define C_HUB_OVER_CURRENT 1
|
|
|
|
#define PORT_CONNECTION 0
|
|
|
|
#define PORT_ENABLE 1
|
|
|
|
#define PORT_SUSPEND 2
|
|
|
|
#define PORT_OVER_CURRENT 3
|
|
|
|
#define PORT_RESET 4
|
|
|
|
#define PORT_POWER 8
|
|
|
|
#define PORT_LOW_SPEED 9
|
|
|
|
#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 PORT_TEST 21
|
|
|
|
#define PORT_INDICATOR 22
|
|
|
|
|
|
|
|
typedef struct _PORT_STATUS_CHANGE
|
|
|
|
{
|
|
|
|
USHORT Status;
|
|
|
|
USHORT Change;
|
|
|
|
} PORT_STATUS_CHANGE, *PPORT_STATUS_CHANGE;
|
|
|
|
|
2011-05-04 12:58:42 +00:00
|
|
|
typedef struct _WORK_ITEM_DATA
|
|
|
|
{
|
|
|
|
WORK_QUEUE_ITEM WorkItem;
|
|
|
|
PVOID Context;
|
|
|
|
} WORK_ITEM_DATA, *PWORK_ITEM_DATA;
|
|
|
|
|
2017-01-27 11:09:36 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Definitions for device's PnP state tracking, all this states are described
|
|
|
|
// in PnP Device States diagram of DDK documentation.
|
|
|
|
//
|
|
|
|
typedef enum _DEVICE_PNP_STATE {
|
|
|
|
|
|
|
|
NotStarted = 0, // Not started
|
|
|
|
Started, // After handling of START_DEVICE IRP
|
|
|
|
StopPending, // After handling of QUERY_STOP IRP
|
|
|
|
Stopped, // After handling of STOP_DEVICE IRP
|
|
|
|
RemovePending, // After handling of QUERY_REMOVE IRP
|
|
|
|
SurpriseRemovePending, // After handling of SURPRISE_REMOVE IRP
|
|
|
|
Deleted, // After handling of REMOVE_DEVICE IRP
|
|
|
|
UnKnown // Unknown state
|
|
|
|
|
|
|
|
} DEVICE_PNP_STATE;
|
|
|
|
|
|
|
|
#define INITIALIZE_PNP_STATE(Data) \
|
|
|
|
(Data).PnPState = NotStarted;\
|
|
|
|
(Data).PreviousPnPState = NotStarted;
|
|
|
|
|
|
|
|
#define SET_NEW_PNP_STATE(Data, state) \
|
|
|
|
(Data).PreviousPnPState = (Data).PnPState;\
|
|
|
|
(Data).PnPState = (state);
|
|
|
|
|
|
|
|
#define RESTORE_PREVIOUS_PNP_STATE(Data) \
|
|
|
|
(Data).PnPState = (Data).PreviousPnPState;
|
|
|
|
|
2011-05-04 01:07:21 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BOOLEAN IsFDO;
|
2017-01-27 11:09:36 +00:00
|
|
|
// We'll track device PnP state via this variables
|
|
|
|
DEVICE_PNP_STATE PnPState;
|
|
|
|
DEVICE_PNP_STATE PreviousPnPState;
|
|
|
|
// Remove lock
|
|
|
|
IO_REMOVE_LOCK RemoveLock;
|
2011-05-04 01:07:21 +00:00
|
|
|
} COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
|
|
|
|
|
|
|
|
typedef struct _HUB_CHILDDEVICE_EXTENSION
|
|
|
|
{
|
|
|
|
COMMON_DEVICE_EXTENSION Common;
|
|
|
|
PDEVICE_OBJECT ParentDeviceObject;
|
2011-05-04 21:45:55 +00:00
|
|
|
PUSB_DEVICE_HANDLE UsbDeviceHandle;
|
2011-05-11 02:25:11 +00:00
|
|
|
ULONG PortNumber;
|
2011-05-08 12:24:26 +00:00
|
|
|
UNICODE_STRING usDeviceId;
|
|
|
|
UNICODE_STRING usInstanceId;
|
|
|
|
UNICODE_STRING usHardwareIds;
|
|
|
|
UNICODE_STRING usCompatibleIds;
|
|
|
|
UNICODE_STRING usTextDescription;
|
|
|
|
UNICODE_STRING usLocationInformation;
|
2011-05-07 14:49:02 +00:00
|
|
|
USB_DEVICE_DESCRIPTOR DeviceDesc;
|
2011-05-08 12:24:26 +00:00
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR FullConfigDesc;
|
2011-05-04 01:07:21 +00:00
|
|
|
UNICODE_STRING SymbolicLinkName;
|
2012-03-04 02:17:13 +00:00
|
|
|
USB_BUS_INTERFACE_USBDI_V2 DeviceInterface;
|
2012-10-24 15:40:46 +00:00
|
|
|
USB_DEVICE_INFORMATION_0 DeviceInformation;
|
2011-05-04 01:07:21 +00:00
|
|
|
} HUB_CHILDDEVICE_EXTENSION, *PHUB_CHILDDEVICE_EXTENSION;
|
|
|
|
|
|
|
|
typedef struct _HUB_DEVICE_EXTENSION
|
|
|
|
{
|
|
|
|
COMMON_DEVICE_EXTENSION Common;
|
|
|
|
PDEVICE_OBJECT LowerDeviceObject;
|
|
|
|
ULONG ChildCount;
|
|
|
|
PDEVICE_OBJECT ChildDeviceObject[USB_MAXCHILDREN];
|
|
|
|
PDEVICE_OBJECT RootHubPhysicalDeviceObject;
|
|
|
|
PDEVICE_OBJECT RootHubFunctionalDeviceObject;
|
|
|
|
|
2017-01-27 11:09:36 +00:00
|
|
|
KGUARDED_MUTEX HubMutexLock;
|
|
|
|
|
2011-05-04 01:07:21 +00:00
|
|
|
ULONG NumberOfHubs;
|
2012-02-08 15:50:52 +00:00
|
|
|
KEVENT ResetComplete;
|
2011-05-04 01:07:21 +00:00
|
|
|
|
|
|
|
PORT_STATUS_CHANGE *PortStatusChange;
|
|
|
|
URB PendingSCEUrb;
|
|
|
|
PIRP PendingSCEIrp;
|
|
|
|
|
|
|
|
USB_BUS_INTERFACE_HUB_V5 HubInterface;
|
|
|
|
USB_BUS_INTERFACE_USBDI_V2 UsbDInterface;
|
|
|
|
|
|
|
|
USB_HUB_DESCRIPTOR HubDescriptor;
|
|
|
|
USB_DEVICE_DESCRIPTOR HubDeviceDescriptor;
|
|
|
|
USB_CONFIGURATION_DESCRIPTOR HubConfigDescriptor;
|
|
|
|
USB_INTERFACE_DESCRIPTOR HubInterfaceDescriptor;
|
|
|
|
USB_ENDPOINT_DESCRIPTOR HubEndPointDescriptor;
|
|
|
|
|
|
|
|
USB_EXTHUB_INFORMATION_0 UsbExtHubInfo;
|
|
|
|
USB_DEVICE_INFORMATION_0 DeviceInformation;
|
|
|
|
|
|
|
|
USBD_CONFIGURATION_HANDLE ConfigurationHandle;
|
|
|
|
USBD_PIPE_HANDLE PipeHandle;
|
|
|
|
PVOID RootHubHandle;
|
2012-03-04 02:17:13 +00:00
|
|
|
|
2011-05-04 01:07:21 +00:00
|
|
|
UNICODE_STRING SymbolicLinkName;
|
2012-10-22 11:33:26 +00:00
|
|
|
ULONG InstanceCount;
|
|
|
|
|
2011-05-04 01:07:21 +00:00
|
|
|
} HUB_DEVICE_EXTENSION, *PHUB_DEVICE_EXTENSION;
|
|
|
|
|
|
|
|
// createclose.c
|
|
|
|
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);
|
|
|
|
|
|
|
|
// fdo.c
|
|
|
|
NTSTATUS
|
|
|
|
USBHUB_FdoHandleDeviceControl(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
USBHUB_FdoHandlePnp(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp);
|
|
|
|
|
|
|
|
// misc.c
|
|
|
|
NTSTATUS
|
|
|
|
ForwardIrpAndWait(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
ForwardIrpAndForget(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp);
|
|
|
|
|
2012-02-29 18:51:07 +00:00
|
|
|
NTSTATUS
|
|
|
|
SubmitRequestToRootHub(
|
|
|
|
IN PDEVICE_OBJECT RootHubDeviceObject,
|
|
|
|
IN ULONG IoControlCode,
|
|
|
|
OUT PVOID OutParameter1,
|
|
|
|
OUT PVOID OutParameter2);
|
|
|
|
|
2012-03-04 02:17:13 +00:00
|
|
|
NTSTATUS
|
|
|
|
FDO_QueryInterface(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN OUT PUSB_BUS_INTERFACE_USBDI_V2 Interface);
|
|
|
|
|
2011-05-04 01:07:21 +00:00
|
|
|
// pdo.c
|
|
|
|
NTSTATUS
|
|
|
|
USBHUB_PdoHandlePnp(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
USBHUB_PdoHandleInternalDeviceControl(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
DumpDeviceDescriptor(
|
|
|
|
PUSB_DEVICE_DESCRIPTOR DeviceDescriptor);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
DumpConfigurationDescriptor(
|
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);
|
2011-05-12 12:58:07 +00:00
|
|
|
|
2011-05-08 12:24:26 +00:00
|
|
|
VOID
|
|
|
|
DumpFullConfigurationDescriptor(
|
|
|
|
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);
|
2011-05-12 12:58:07 +00:00
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
GetPortStatusAndChange(
|
|
|
|
IN PDEVICE_OBJECT RootHubDeviceObject,
|
|
|
|
IN ULONG PortId,
|
|
|
|
OUT PPORT_STATUS_CHANGE StatusChange);
|
2012-02-29 18:51:07 +00:00
|
|
|
|
|
|
|
// hub_fdo.c
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
USBHUB_ParentFDOStartDevice(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
2013-12-21 19:15:13 +00:00
|
|
|
IN PIRP Irp);
|
2014-02-06 11:18:34 +00:00
|
|
|
|
|
|
|
#endif /* _USBHUB_H_ */
|