ReactOS  0.4.14-dev-293-g2b39b42
usbccgp.h File Reference
#include <wdm.h>
#include <hubbusif.h>
#include <usbbusif.h>
#include <usbdlib.h>
#include <stdio.h>
Include dependency graph for usbccgp.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  FDO_DEVICE_EXTENSION
 
struct  PDO_DEVICE_EXTENSION
 

Macros

#define USBCCPG_TAG   'cbsu'
 

Typedefs

typedef struct COMMON_DEVICE_EXTENSIONPCOMMON_DEVICE_EXTENSION
 
typedef struct FDO_DEVICE_EXTENSIONPFDO_DEVICE_EXTENSION
 
typedef struct PDO_DEVICE_EXTENSIONPPDO_DEVICE_EXTENSION
 

Functions

VOID DumpConfigurationDescriptor (IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
 
NTSTATUS USBCCGP_GetDescriptors (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS USBCCGP_SelectConfiguration (IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI USBCCGP_GetDescriptor (IN PDEVICE_OBJECT DeviceObject, IN UCHAR DescriptorType, IN ULONG DescriptorLength, IN UCHAR DescriptorIndex, IN LANGID LanguageId, OUT PVOID *OutDescriptor)
 
NTSTATUS NTAPI USBCCGP_GetStringDescriptor (IN PDEVICE_OBJECT DeviceObject, IN ULONG DescriptorLength, IN UCHAR DescriptorIndex, IN LANGID LanguageId, OUT PVOID *OutDescriptor)
 
ULONG CountInterfaceDescriptors (IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
 
NTSTATUS AllocateInterfaceDescriptorsArray (IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, OUT PUSB_INTERFACE_DESCRIPTOR **OutArray)
 
NTSTATUS NTAPI USBCCGP_SyncForwardIrp (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS USBCCGP_SyncUrbRequest (IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
 
PVOID AllocateItem (IN POOL_TYPE PoolType, IN ULONG ItemSize)
 
VOID FreeItem (IN PVOID Item)
 
VOID DumpFunctionDescriptor (IN PUSBC_FUNCTION_DESCRIPTOR FunctionDescriptor, IN ULONG FunctionDescriptorCount)
 
NTSTATUS FDO_Dispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS PDO_Dispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS USBCCGP_QueryInterface (IN PDEVICE_OBJECT DeviceObject, OUT PUSBC_DEVICE_CONFIGURATION_INTERFACE_V1 BusInterface)
 
NTSTATUS USBCCGP_EnumerateFunctions (IN PDEVICE_OBJECT DeviceObject)
 

Macro Definition Documentation

◆ USBCCPG_TAG

#define USBCCPG_TAG   'cbsu'

Definition at line 39 of file usbccgp.h.

Typedef Documentation

◆ PCOMMON_DEVICE_EXTENSION

◆ PFDO_DEVICE_EXTENSION

◆ PPDO_DEVICE_EXTENSION

Function Documentation

◆ AllocateInterfaceDescriptorsArray()

NTSTATUS AllocateInterfaceDescriptorsArray ( IN PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor,
OUT PUSB_INTERFACE_DESCRIPTOR **  OutArray 
)

Definition at line 227 of file descriptor.c.

230 {
231  PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
232  ULONG Count = 0;
234 
235  //
236  // allocate array
237  //
238  Array = AllocateItem(NonPagedPool, sizeof(PUSB_INTERFACE_DESCRIPTOR) * ConfigurationDescriptor->bNumInterfaces);
239  if (!Array)
241 
242  //
243  // enumerate all interfaces
244  //
245  Count = 0;
246  do
247  {
248  //
249  // find next descriptor
250  //
251  InterfaceDescriptor = USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor, ConfigurationDescriptor, Count, 0, -1, -1, -1);
252  if (!InterfaceDescriptor)
253  break;
254 
255  //
256  // store descriptor
257  //
258  Array[Count] = InterfaceDescriptor;
259  Count++;
260 
261  }while(TRUE);
262 
263  //
264  // store result
265  //
266  *OutArray = Array;
267 
268  //
269  // done
270  //
271  return STATUS_SUCCESS;
272 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
PUSB_INTERFACE_DESCRIPTOR NTAPI USBD_ParseConfigurationDescriptorEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PVOID StartPosition, LONG InterfaceNumber, LONG AlternateSetting, LONG InterfaceClass, LONG InterfaceSubClass, LONG InterfaceProtocol)
Definition: usbd.c:496
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by USBCCGP_EnumWithAudioLegacy().

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN ULONG  ItemSize 
)

Definition at line 30 of file misc.c.

33 {
35  if (!Item)
36  return Item;
37 
39  return Item;
40 }
#define TAG_KS
Definition: misc.c:14
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:998
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444

◆ CountInterfaceDescriptors()

ULONG CountInterfaceDescriptors ( IN PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor)

◆ DumpConfigurationDescriptor()

VOID DumpConfigurationDescriptor ( IN PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor)

◆ DumpFunctionDescriptor()

VOID DumpFunctionDescriptor ( IN PUSBC_FUNCTION_DESCRIPTOR  FunctionDescriptor,
IN ULONG  FunctionDescriptorCount 
)

Definition at line 160 of file misc.c.

163 {
164  ULONG Index, SubIndex;
165 
166 
167  DPRINT1("FunctionCount %lu\n", FunctionDescriptorCount);
168  for (Index = 0; Index < FunctionDescriptorCount; Index++)
169  {
170  DPRINT1("Function %lu\n", Index);
171  DPRINT1("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
172  DPRINT1("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
173  DPRINT1("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
174  DPRINT1("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
175  DPRINT1("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
176 
177  for(SubIndex = 0; SubIndex < FunctionDescriptor[Index].NumberOfInterfaces; SubIndex++)
178  {
179  DPRINT1(" Index %lu Interface %p\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
180  DPRINT1(" Index %lu Interface InterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
181  DPRINT1(" Index %lu Interface Alternate %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting );
182  DPRINT1(" Index %lu bLength %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bLength);
183  DPRINT1(" Index %lu bDescriptorType %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bDescriptorType);
184  DPRINT1(" Index %lu bInterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
185  DPRINT1(" Index %lu bAlternateSetting %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
186  DPRINT1(" Index %lu bNumEndpoints %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bNumEndpoints);
187  DPRINT1(" Index %lu bInterfaceClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceClass);
188  DPRINT1(" Index %lu bInterfaceSubClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceSubClass);
189  DPRINT1(" Index %lu bInterfaceProtocol %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceProtocol);
190  DPRINT1(" Index %lu iInterface %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->iInterface);
191  }
192  }
193 }
static const UCHAR Index[8]
Definition: usbohci.c:18
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1

Referenced by FDO_StartDevice().

◆ FDO_Dispatch()

NTSTATUS FDO_Dispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 615 of file fdo.c.

618 {
619  PIO_STACK_LOCATION IoStack;
621  PFDO_DEVICE_EXTENSION FDODeviceExtension;
622 
623  /* Get device extension */
624  FDODeviceExtension = DeviceObject->DeviceExtension;
625  ASSERT(FDODeviceExtension->Common.IsFDO);
626 
627  /* Get stack location */
629 
630  switch(IoStack->MajorFunction)
631  {
632  case IRP_MJ_PNP:
633  return FDO_HandlePnp(DeviceObject, Irp);
636  case IRP_MJ_POWER:
639  return PoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
642  default:
643  DPRINT1("FDO_Dispatch Function %x not implemented\n", IoStack->MajorFunction);
644  ASSERT(FALSE);
645  Status = Irp->IoStatus.Status;
647  return Status;
648  }
649 
650 }
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS FDO_HandleInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:563
#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
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_POWER
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:80
#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
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
NTSTATUS FDO_HandlePnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:374
#define IO_NO_INCREMENT
Definition: iotypes.h:566
NTSTATUS FDO_HandleSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:599

Referenced by USBCCGP_Dispatch().

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 43 of file misc.c.

45 {
46  ExFreePool(Item);
47 }
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ PDO_Dispatch()

NTSTATUS PDO_Dispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 1075 of file pdo.c.

1078 {
1079  PIO_STACK_LOCATION IoStack;
1080  NTSTATUS Status;
1081 
1082  /* get stack location */
1083  IoStack = IoGetCurrentIrpStackLocation(Irp);
1084 
1085  switch(IoStack->MajorFunction)
1086  {
1087  case IRP_MJ_PNP:
1088  return PDO_HandlePnp(DeviceObject, Irp);
1091  case IRP_MJ_POWER:
1093  Irp->IoStatus.Status = STATUS_SUCCESS;
1095  return STATUS_SUCCESS;
1096  default:
1097  DPRINT1("PDO_Dispatch Function %x not implemented\n", IoStack->MajorFunction);
1098  Status = Irp->IoStatus.Status;
1100  return Status;
1101  }
1102 }
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS PDO_HandlePnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:316
#define IoCompleteRequest
Definition: irp.c:1240
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_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
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS PDO_HandleInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:924

Referenced by USBCCGP_Dispatch().

◆ USBCCGP_EnumerateFunctions()

NTSTATUS USBCCGP_EnumerateFunctions ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 829 of file function.c.

831 {
833  PFDO_DEVICE_EXTENSION FDODeviceExtension;
834 
835  //
836  // get device extension
837  //
838  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
839  ASSERT(FDODeviceExtension->Common.IsFDO);
840 
841  //
842  // first try with filter driver
843  //
845  if (NT_SUCCESS(Status))
846  {
847  //
848  // succeeded
849  //
850  return Status;
851  }
852 
853  //
854  // enumerate functions with interface association descriptor
855  //
857  if (NT_SUCCESS(Status))
858  {
859  //
860  // succeeded
861  //
862  return Status;
863  }
864 
865 #if 0
866  //
867  // try with union function descriptors
868  //
870  if (NT_SUCCESS(Status))
871  {
872  //
873  // succeeded
874  //
875  return Status;
876  }
877 #endif
878 
879  //
880  // try with legacy audio methods
881  //
883  if (NT_SUCCESS(Status))
884  {
885  //
886  // succeeded
887  //
888  return Status;
889  }
890 
891  //
892  // try with legacy enumeration
893  //
895 }
LONG NTSTATUS
Definition: precomp.h:26
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
NTSTATUS USBCCGP_CustomEnumWithInterface(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:97
PVOID DeviceExtension
Definition: env_spec_w32.h:418
NTSTATUS USBCCGP_EnumWithUnionFunctionDescriptors(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:702
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS USBCCGP_LegacyEnum(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:607
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:80
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS USBCCGP_EnumWithAssociationDescriptor(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:442
NTSTATUS USBCCGP_EnumWithAudioLegacy(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:710

Referenced by FDO_StartDevice().

◆ USBCCGP_GetDescriptor()

NTSTATUS NTAPI USBCCGP_GetDescriptor ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  DescriptorType,
IN ULONG  DescriptorLength,
IN UCHAR  DescriptorIndex,
IN LANGID  LanguageId,
OUT PVOID OutDescriptor 
)

Definition at line 19 of file descriptor.c.

26 {
27  PURB Urb;
30 
31  //
32  // sanity checks
33  //
35  ASSERT(OutDescriptor);
36  ASSERT(DescriptorLength);
37 
38  //
39  // first allocate descriptor buffer
40  //
41  Descriptor = AllocateItem(NonPagedPool, DescriptorLength);
42  if (!Descriptor)
43  {
44  //
45  // no memory
46  //
48  }
49 
50  //
51  // allocate urb
52  //
53  Urb = (PURB) AllocateItem(NonPagedPool, sizeof(URB));
54  if (!Urb)
55  {
56  //
57  // no memory
58  //
61  }
62 
63  //
64  // initialize urb
65  //
67  sizeof(Urb->UrbControlDescriptorRequest),
69  DescriptorIndex,
70  LanguageId,
71  Descriptor,
72  NULL,
73  DescriptorLength,
74  NULL);
75 
76  //
77  // submit urb
78  //
80 
81  //
82  // free urb
83  //
84  FreeItem(Urb);
85 
86  if (NT_SUCCESS(Status))
87  {
88  //
89  // store result
90  //
91  *OutDescriptor = Descriptor;
92  }
93 
94  //
95  // done
96  //
97  return Status;
98 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _URB * PURB
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
Definition: usb.h:529
NTSTATUS USBCCGP_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:75
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
_In_ ULONG _In_ PVOID _In_ LONG DescriptorType
Definition: usbdlib.h:145
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by PDO_HandleInternalDeviceControl(), USBCCGP_GetDescriptors(), and USBCCGP_GetStringDescriptor().

◆ USBCCGP_GetDescriptors()

NTSTATUS USBCCGP_GetDescriptors ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 160 of file descriptor.c.

162 {
164  PFDO_DEVICE_EXTENSION DeviceExtension;
165  USHORT DescriptorLength;
166 
167  //
168  // get device extension
169  //
171 
172  //
173  // first get device descriptor
174  //
175  Status = USBCCGP_GetDescriptor(DeviceExtension->NextDeviceObject, USB_DEVICE_DESCRIPTOR_TYPE, sizeof(USB_DEVICE_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->DeviceDescriptor);
176  if (!NT_SUCCESS(Status))
177  {
178  //
179  // failed to get device descriptor
180  //
181  DeviceExtension->DeviceDescriptor = NULL;
182  return Status;
183  }
184 
185  //
186  // now get basic configuration descriptor
187  //
188  Status = USBCCGP_GetDescriptor(DeviceExtension->NextDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, sizeof(USB_CONFIGURATION_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor);
189  if (!NT_SUCCESS(Status))
190  {
191  //
192  // failed to get configuration descriptor
193  //
194  FreeItem(DeviceExtension->DeviceDescriptor);
195  DeviceExtension->DeviceDescriptor = NULL;
196  return Status;
197  }
198 
199  //
200  // backup length
201  //
202  DescriptorLength = DeviceExtension->ConfigurationDescriptor->wTotalLength;
203 
204  //
205  // release basic descriptor
206  //
207  FreeItem(DeviceExtension->ConfigurationDescriptor);
208  DeviceExtension->ConfigurationDescriptor = NULL;
209 
210  //
211  // allocate full descriptor
212  //
213  Status = USBCCGP_GetDescriptor(DeviceExtension->NextDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, DescriptorLength, 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor);
214  if (!NT_SUCCESS(Status))
215  {
216  //
217  // failed to get configuration descriptor
218  //
219  FreeItem(DeviceExtension->DeviceDescriptor);
220  DeviceExtension->DeviceDescriptor = NULL;
221  return Status;
222  }
223  return Status;
224 }
LONG NTSTATUS
Definition: precomp.h:26
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI USBCCGP_GetDescriptor(IN PDEVICE_OBJECT DeviceObject, IN UCHAR DescriptorType, IN ULONG DescriptorLength, IN UCHAR DescriptorIndex, IN LANGID LanguageId, OUT PVOID *OutDescriptor)
Definition: descriptor.c:19
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned short USHORT
Definition: pedump.c:61

Referenced by FDO_StartDevice().

◆ USBCCGP_GetStringDescriptor()

NTSTATUS NTAPI USBCCGP_GetStringDescriptor ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  DescriptorLength,
IN UCHAR  DescriptorIndex,
IN LANGID  LanguageId,
OUT PVOID OutDescriptor 
)

Definition at line 102 of file descriptor.c.

108 {
110  PUSB_STRING_DESCRIPTOR StringDescriptor;
111  ULONG Size;
112  PVOID Buffer;
113 
114  // retrieve descriptor
115  Status = USBCCGP_GetDescriptor(DeviceObject, USB_STRING_DESCRIPTOR_TYPE, DescriptorLength, DescriptorIndex, LanguageId, OutDescriptor);
116  if (!NT_SUCCESS(Status))
117  {
118  // failed
119  return Status;
120  }
121 
122  // get descriptor structure
123  StringDescriptor = (PUSB_STRING_DESCRIPTOR)*OutDescriptor;
124 
125  // sanity check
126  ASSERT(StringDescriptor->bLength < DescriptorLength - 2);
127 
128  if (StringDescriptor->bLength == 2)
129  {
130  // invalid descriptor
131  FreeItem(StringDescriptor);
133  }
134 
135  // calculate size
136  Size = StringDescriptor->bLength + sizeof(WCHAR);
137 
138  // allocate buffer
140  if (!Buffer)
141  {
142  // no memory
143  FreeItem(StringDescriptor);
145  }
146 
147  // copy result
148  RtlCopyMemory(Buffer, StringDescriptor->bString, Size - FIELD_OFFSET(USB_STRING_DESCRIPTOR, bString));
149 
150  // free buffer
151  FreeItem(StringDescriptor);
152 
153  // store result
154  *OutDescriptor = (PVOID)Buffer;
155  return STATUS_SUCCESS;
156 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI USBCCGP_GetDescriptor(IN PDEVICE_OBJECT DeviceObject, IN UCHAR DescriptorType, IN ULONG DescriptorLength, IN UCHAR DescriptorIndex, IN LANGID LanguageId, OUT PVOID *OutDescriptor)
Definition: descriptor.c:19
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct _USB_STRING_DESCRIPTOR * PUSB_STRING_DESCRIPTOR
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159

Referenced by USBCCG_InitIdsWithInterfaceDescriptor(), and USBCCGP_InitFunctionDescriptor().

◆ USBCCGP_QueryInterface()

NTSTATUS USBCCGP_QueryInterface ( IN PDEVICE_OBJECT  DeviceObject,
OUT PUSBC_DEVICE_CONFIGURATION_INTERFACE_V1  BusInterface 
)

Definition at line 18 of file function.c.

21 {
22  KEVENT Event;
24  PIRP Irp;
26  PIO_STACK_LOCATION Stack;
27 
28  /* Sanity checks */
30 
31  /* Initialize event */
33 
34  /* Init interface */
36  BusInterface->Version = USBC_DEVICE_CONFIGURATION_INTERFACE_VERSION_1;
37  BusInterface->Size = sizeof(USBC_DEVICE_CONFIGURATION_INTERFACE_V1);
38 
39  /* Create irp */
42  NULL,
43  0,
44  NULL,
45  &Event,
46  &IoStatus);
47 
48  //
49  // was irp built
50  //
51  if (Irp == NULL)
52  {
53  //
54  // no memory
55  //
57  }
58 
59  //
60  // initialize request
61  //
63  Stack->MajorFunction = IRP_MJ_PNP;
65  Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
66  Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&USB_BUS_INTERFACE_USBC_CONFIGURATION_GUID;
67  Stack->Parameters.QueryInterface.Version = 2;
68  Stack->Parameters.QueryInterface.Interface = (PINTERFACE)&BusInterface;
69  Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
70  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
71 
72  //
73  // call driver
74  //
76 
77  //
78  // did operation complete
79  //
80  if (Status == STATUS_PENDING)
81  {
82  //
83  // wait for completion
84  //
86 
87  //
88  // collect status
89  //
90  Status = IoStatus.Status;
91  }
92 
93  return Status;
94 }
#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:435
smooth NULL
Definition: ftsmooth.c:416
struct _INTERFACE * PINTERFACE
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_QUERY_INTERFACE
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__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
#define USBC_DEVICE_CONFIGURATION_INTERFACE_VERSION_1
Definition: usbbusif.h:199
struct _USBC_DEVICE_CONFIGURATION_INTERFACE_V1 USBC_DEVICE_CONFIGURATION_INTERFACE_V1
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
GUID * LPGUID
Definition: guiddef.h:81

Referenced by FDO_StartDevice().

◆ USBCCGP_SelectConfiguration()

NTSTATUS USBCCGP_SelectConfiguration ( IN PDEVICE_OBJECT  DeviceObject,
IN PFDO_DEVICE_EXTENSION  DeviceExtension 
)

Definition at line 467 of file descriptor.c.

470 {
471  PUSBD_INTERFACE_INFORMATION InterfaceInformation;
473  PURB Urb;
474  ULONG Index;
475 
476  //
477  // now scan configuration descriptors
478  //
479  Status = USBCCGP_ScanConfigurationDescriptor(DeviceExtension, DeviceExtension->ConfigurationDescriptor);
480  if (!NT_SUCCESS(Status))
481  {
482  //
483  // failed to scan
484  //
485  return Status;
486  }
487 
488  //
489  // now allocate the urb
490  //
491  Urb = USBD_CreateConfigurationRequestEx(DeviceExtension->ConfigurationDescriptor, DeviceExtension->InterfaceList);
492  if (!Urb)
493  {
494  //
495  // no memory
496  //
498  }
499 
500  //
501  // submit urb
502  //
503  Status = USBCCGP_SyncUrbRequest(DeviceExtension->NextDeviceObject, Urb);
504  if (!NT_SUCCESS(Status))
505  {
506  //
507  // failed to set configuration
508  //
509  DPRINT1("USBCCGP_SyncUrbRequest failed to set interface %x\n", Status);
510  ExFreePool(Urb);
511  return Status;
512  }
513 
514  //
515  // get interface information
516  //
517  InterfaceInformation = &Urb->UrbSelectConfiguration.Interface;
518  for(Index = 0; Index < DeviceExtension->InterfaceListCount; Index++)
519  {
520  //
521  // allocate buffer to store interface information
522  //
523  DeviceExtension->InterfaceList[Index].Interface = AllocateItem(NonPagedPool, InterfaceInformation->Length);
524  if (!DeviceExtension->InterfaceList[Index].Interface)
525  {
526  //
527  // no memory
528  //
530  }
531 
532  //
533  // copy interface information
534  //
535  RtlCopyMemory(DeviceExtension->InterfaceList[Index].Interface, InterfaceInformation, InterfaceInformation->Length);
536 
537  //
538  // move to next interface
539  //
540  InterfaceInformation = (PUSBD_INTERFACE_INFORMATION)((ULONG_PTR)InterfaceInformation + InterfaceInformation->Length);
541  }
542 
543 
544  //
545  // store pipe handle
546  //
547  DeviceExtension->ConfigurationHandle = Urb->UrbSelectConfiguration.ConfigurationHandle;
548 
549  //
550  // free interface list & urb
551  //
552  ExFreePool(Urb);
553 
554  //
555  // done
556  //
557  return Status;
558 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
Status
Definition: gdiplustypes.h:24
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
Definition: usb.h:529
NTSTATUS USBCCGP_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:75
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
PURB NTAPI USBD_CreateConfigurationRequestEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PUSBD_INTERFACE_LIST_ENTRY InterfaceList)
Definition: usbd.c:329
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS NTAPI USBCCGP_ScanConfigurationDescriptor(IN OUT PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
Definition: descriptor.c:311

Referenced by FDO_StartDevice().

◆ USBCCGP_SyncForwardIrp()

NTSTATUS NTAPI USBCCGP_SyncForwardIrp ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 36 of file misc.c.

39 {
40  KEVENT Event;
42 
43  /* Initialize event */
45 
46  /* Copy irp stack location */
48 
49  /* Set completion routine */
52  &Event,
53  TRUE,
54  TRUE,
55  TRUE);
56 
57  /* Call driver */
59 
60  /* Check if pending */
61  if (Status == STATUS_PENDING)
62  {
63  /* Wait for the request to finish */
65 
66  /* Copy status code */
67  Status = Irp->IoStatus.Status;
68  }
69 
70  /* Done */
71  return Status;
72 }
#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
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: misc.c:22
#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 FDO_DeviceRelations(), FDO_HandlePnp(), FDO_HandleResetCyclePort(), FDO_StartDevice(), and USBCCGP_PdoHandleQueryId().

◆ USBCCGP_SyncUrbRequest()

NTSTATUS USBCCGP_SyncUrbRequest ( IN PDEVICE_OBJECT  DeviceObject,
OUT PURB  UrbRequest 
)

Definition at line 75 of file misc.c.

78 {
79  PIRP Irp;
80  PIO_STACK_LOCATION IoStack;
81  KEVENT Event;
83 
84  /* Allocate irp */
86  if (!Irp)
87  {
88  /* No memory */
90  }
91 
92  /* Initialize event */
94 
95  /* Get next stack location */
96  IoStack = IoGetNextIrpStackLocation(Irp);
97 
98  /* Initialize stack location */
100  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
101  IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
102  IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
103  Irp->IoStatus.Status = STATUS_SUCCESS;
104 
105  /* Setup completion routine */
108  &Event,
109  TRUE,
110  TRUE,
111  TRUE);
112 
113  /* Call driver */
115 
116  /* Check if request is pending */
117  if (Status == STATUS_PENDING)
118  {
119  /* Wait for completion */
121 
122  /* Update status */
123  Status = Irp->IoStatus.Status;
124  }
125 
126  /* Free irp */
127  IoFreeIrp(Irp);
128 
129  /* Done */
130  return Status;
131 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_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
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: misc.c:22
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
__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
#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
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
static PVOID
Definition: misc.c:50
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by FDO_CloseConfiguration(), USBCCGP_GetDescriptor(), USBCCGP_PDOSelectConfiguration(), USBCCGP_SelectConfiguration(), and USBCCGP_SelectInterface().