ReactOS 0.4.15-dev-8102-g108db8f
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 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{
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);
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 NonPagedPool
Definition: env_spec_w32.h:307
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
int Count
Definition: noreturn.cpp:7
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2334

Referenced by USBCCGP_EnumWithAudioLegacy().

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN ULONG  ItemSize 
)

Definition at line 29 of file misc.c.

32{
33 return ExAllocatePoolZero(PoolType, NumberOfBytes, TAG_KS);
34}
#define TAG_KS
Definition: misc.c:14
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036

◆ 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 111 of file misc.c.

114{
115 ULONG Index, SubIndex;
116
117 DPRINT("FunctionCount %lu\n", FunctionDescriptorCount);
118 for (Index = 0; Index < FunctionDescriptorCount; Index++)
119 {
120 DPRINT("Function %lu\n", Index);
121 DPRINT("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
122 DPRINT("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
123 DPRINT("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
124 DPRINT("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
125 DPRINT("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
126
127 for(SubIndex = 0; SubIndex < FunctionDescriptor[Index].NumberOfInterfaces; SubIndex++)
128 {
129 DPRINT(" Index %lu Interface %p\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
130 DPRINT(" Index %lu Interface InterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
131 DPRINT(" Index %lu Interface Alternate %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting );
132 DPRINT(" Index %lu bLength %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bLength);
133 DPRINT(" Index %lu bDescriptorType %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bDescriptorType);
134 DPRINT(" Index %lu bInterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
135 DPRINT(" Index %lu bAlternateSetting %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
136 DPRINT(" Index %lu bNumEndpoints %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bNumEndpoints);
137 DPRINT(" Index %lu bInterfaceClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceClass);
138 DPRINT(" Index %lu bInterfaceSubClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceSubClass);
139 DPRINT(" Index %lu bInterfaceProtocol %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceProtocol);
140 DPRINT(" Index %lu iInterface %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->iInterface);
141 }
142 }
143}
#define DPRINT
Definition: sndvol32.h:73
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by FDO_StartDevice().

◆ FDO_Dispatch()

NTSTATUS FDO_Dispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 633 of file fdo.c.

636{
637 PIO_STACK_LOCATION IoStack;
639 PFDO_DEVICE_EXTENSION FDODeviceExtension;
640
641 /* Get device extension */
642 FDODeviceExtension = DeviceObject->DeviceExtension;
643 ASSERT(FDODeviceExtension->Common.IsFDO);
644
645 /* Get stack location */
647
648 switch(IoStack->MajorFunction)
649 {
650 case IRP_MJ_PNP:
654 case IRP_MJ_POWER:
657 return PoCallDriver(FDODeviceExtension->NextDeviceObject, Irp);
660 default:
661 DPRINT1("FDO_Dispatch Function %x not implemented\n", IoStack->MajorFunction);
662 ASSERT(FALSE);
663 Status = Irp->IoStatus.Status;
665 return Status;
666 }
667
668}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:84
NTSTATUS FDO_HandleSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:617
NTSTATUS FDO_HandleInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:581
NTSTATUS FDO_HandlePnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fdo.c:382
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER

Referenced by USBCCGP_Dispatch().

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 37 of file misc.c.

39{
41}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ WDFCOLLECTION _In_ WDFOBJECT Item

◆ PDO_Dispatch()

NTSTATUS PDO_Dispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 1125 of file pdo.c.

1128{
1129 PIO_STACK_LOCATION IoStack;
1131
1132 /* get stack location */
1134
1135 switch(IoStack->MajorFunction)
1136 {
1137 case IRP_MJ_PNP:
1141 case IRP_MJ_POWER:
1143 default:
1144 DPRINT1("PDO_Dispatch Function %x not implemented\n", IoStack->MajorFunction);
1145 Status = Irp->IoStatus.Status;
1147 return Status;
1148 }
1149}
NTSTATUS PDO_HandleInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:950
NTSTATUS PDO_HandlePower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:1100
NTSTATUS PDO_HandlePnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:342

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}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
NTSTATUS USBCCGP_EnumWithAudioLegacy(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:710
NTSTATUS USBCCGP_EnumWithAssociationDescriptor(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:442
NTSTATUS USBCCGP_EnumWithUnionFunctionDescriptors(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:702
NTSTATUS USBCCGP_CustomEnumWithInterface(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:97
NTSTATUS USBCCGP_LegacyEnum(IN PDEVICE_OBJECT DeviceObject)
Definition: function.c:607

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,
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 NULL
Definition: types.h:112
NTSTATUS USBCCGP_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:35
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
Definition: usb.h:529
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
struct _URB * PURB
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
_In_ ULONG _In_ PVOID _In_ LONG DescriptorType
Definition: usbdlib.h:160
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

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 //
170 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
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}
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
unsigned short USHORT
Definition: pedump.c:61
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49

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;
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}
Definition: bufpool.h:45
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
struct _USB_STRING_DESCRIPTOR * PUSB_STRING_DESCRIPTOR
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
__wchar_t WCHAR
Definition: xmlstorage.h:180

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{
24 PIRP Irp;
27
28 /* Sanity checks */
30
31 /* Initialize event */
33
34 /* Init interface */
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;
64 Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
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 //
81 {
82 //
83 // wait for completion
84 //
86
87 //
88 // collect status
89 //
90 Status = IoStatus.Status;
91 }
92
93 return Status;
94}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
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
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
GUID * LPGUID
Definition: guiddef.h:81
struct _INTERFACE * PINTERFACE
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _USBC_DEVICE_CONFIGURATION_INTERFACE_V1 USBC_DEVICE_CONFIGURATION_INTERFACE_V1
#define USBC_DEVICE_CONFIGURATION_INTERFACE_VERSION_1
Definition: usbbusif.h:199
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MN_QUERY_INTERFACE
struct _BUS_INTERFACE_STANDARD BUS_INTERFACE_STANDARD
@ Executive
Definition: ketypes.h:415

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}
NTSTATUS NTAPI USBCCGP_ScanConfigurationDescriptor(IN OUT PFDO_DEVICE_EXTENSION FDODeviceExtension, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
Definition: descriptor.c:311
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
PURB NTAPI USBD_CreateConfigurationRequestEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PUSBD_INTERFACE_LIST_ENTRY InterfaceList)
Definition: usbd.c:329

Referenced by FDO_StartDevice().

◆ USBCCGP_SyncUrbRequest()

NTSTATUS USBCCGP_SyncUrbRequest ( IN PDEVICE_OBJECT  DeviceObject,
OUT PURB  UrbRequest 
)

Definition at line 35 of file misc.c.

38{
39 PIRP Irp;
40 PIO_STACK_LOCATION IoStack;
43
44 /* Allocate irp */
45 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
46 if (!Irp)
47 {
48 /* No memory */
50 }
51
52 /* Initialize event */
54
55 /* Get next stack location */
57
58 /* Initialize stack location */
61 IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
62 IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
63 Irp->IoStatus.Status = STATUS_SUCCESS;
64
65 /* Setup completion routine */
68 &Event,
69 TRUE,
70 TRUE,
71 TRUE);
72
73 /* Call driver */
75
76 /* Check if request is pending */
78 {
79 /* Wait for completion */
81
82 /* Update status */
83 Status = Irp->IoStatus.Status;
84 }
85
86 /* Free irp */
88
89 /* Done */
90 return Status;
91}
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: misc.c:22
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
union _IO_STACK_LOCATION::@1567 Parameters
struct _IO_STACK_LOCATION::@1567::@1568 DeviceIoControl
struct _IO_STACK_LOCATION::@3982::@4021 Others
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32

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