ReactOS 0.4.15-dev-7953-g1f49173
usbutil.hpp File Reference

Go to the source code of this file.

Enumerations

enum  FxUsbValidateDescriptorOp { FxUsbValidateDescriptorOpEqual , FxUsbValidateDescriptorOpAtLeast }
 

Functions

BOOLEAN __inline FxBitArraySet (__inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR BitArray, __in UCHAR BitNumber)
 
VOID __inline FxBitArrayClear (__inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR BitArray, __in UCHAR BitNumber)
 
VOID FxFormatUsbRequest (__in FxRequestBase *Request, __in PURB Urb, __in FX_URB_TYPE FxUrbType, __drv_when(FxUrbType==FxUrbTypeUsbdAllocated, __in) __drv_when(FxUrbType !=FxUrbTypeUsbdAllocated, __in_opt) USBD_HANDLE UsbdHandle)
 
NTSTATUS FxFormatUrbRequest (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxIoTarget *Target, __in FxRequestBase *Request, __in FxRequestBuffer *Buffer, __in FX_URB_TYPE FxUrbType, __drv_when(FxUrbType==FxUrbTypeUsbdAllocated, __in) __drv_when(FxUrbType !=FxUrbTypeUsbdAllocated, __in_opt) USBD_HANDLE UsbdHandle)
 
PUSB_INTERFACE_DESCRIPTOR FxUsbParseConfigurationDescriptor (__in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in UCHAR InterfaceNumber=-1, __in UCHAR AlternateSetting=1)
 
PURB FxUsbCreateConfigRequest (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in PUSBD_INTERFACE_LIST_ENTRY InterfaceList, __in ULONG DefaultMaxPacketSize)
 
NTSTATUS FxUsbValidateConfigDescriptorHeaders (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, __in size_t ConfigDescriptorLength)
 
PUSB_COMMON_DESCRIPTOR FxUsbFindDescriptorType (__in PVOID Buffer, __in size_t BufferLength, __in PVOID Start, __in LONG DescriptorType)
 
NTSTATUS FxUsbValidateDescriptorType (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, __in PVOID Start, __in PVOID End, __in LONG DescriptorType, __in size_t SizeToValidate, __in FxUsbValidateDescriptorOp Op, __in ULONG MaximumNumDescriptorsToValidate)
 
VOID FxUsbUmFormatRequest (__in FxRequestBase *Request, __in_xcount(Urb->Length) PUMURB_HEADER Urb, __in IWudfFile *HostFile, __in BOOLEAN Reuse=FALSE)
 
VOID FxUsbUmInitDescriptorUrb (__inout PUMURB UmUrb, __in WINUSB_INTERFACE_HANDLE WinUsbHandle, __in UCHAR DescriptorType, __in ULONG BufferLength, __in PVOID Buffer)
 
VOID FxUsbUmInitControlTransferUrb (__inout PUMURB UmUrb, __in WINUSB_INTERFACE_HANDLE WinUsbHandle, __in ULONG BufferLength, __in PVOID Buffer)
 
VOID FxUsbUmInitInformationUrb (__inout PUMURB UmUrb, __in WINUSB_INTERFACE_HANDLE WinUsbHandle, __in ULONG BufferLength, __in PVOID Buffer)
 

Enumeration Type Documentation

◆ FxUsbValidateDescriptorOp

Enumerator
FxUsbValidateDescriptorOpEqual 
FxUsbValidateDescriptorOpAtLeast 

Definition at line 126 of file usbutil.hpp.

126 {
129};
@ FxUsbValidateDescriptorOpAtLeast
Definition: usbutil.hpp:128
@ FxUsbValidateDescriptorOpEqual
Definition: usbutil.hpp:127

Function Documentation

◆ FxBitArrayClear()

VOID __inline FxBitArrayClear ( __inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR  BitArray,
__in UCHAR  BitNumber 
)

Definition at line 49 of file usbutil.hpp.

64{
66 UCHAR bit;
67
68 index = BitNumber / sizeof(UCHAR);
69 bit = (UCHAR) (1 << (BitNumber % sizeof(UCHAR)) );
70
71 BitArray[index] &= ~bit;
72}
#define index(s, c)
Definition: various.h:29
GLuint index
Definition: glext.h:6031
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ FxBitArraySet()

BOOLEAN __inline FxBitArraySet ( __inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR  BitArray,
__in UCHAR  BitNumber 
)

Definition at line 9 of file usbutil.hpp.

29{
31 UCHAR bit;
32
33 index = (BitNumber) / sizeof(UCHAR);
34 bit = (UCHAR) (1 << (BitNumber % sizeof(UCHAR)) );
35
36 if ((BitArray[index] & bit) == 0x0) {
37 //
38 // bit not set
39 //
40 BitArray[index] |= bit;
41 return FALSE;
42 }
43
44 return TRUE;
45}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

Referenced by FxUsbDevice::CreateInterfaces(), and FxUsbDevice::SelectConfigMulti().

◆ FxFormatUrbRequest()

NTSTATUS FxFormatUrbRequest ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in FxIoTarget Target,
__in FxRequestBase Request,
__in FxRequestBuffer Buffer,
__in FX_URB_TYPE  FxUrbType,
__drv_when(FxUrbType==FxUrbTypeUsbdAllocated, __in) __drv_when(FxUrbType !=FxUrbTypeUsbdAllocated, __in_opt) USBD_HANDLE  UsbdHandle 
)

Definition at line 62 of file usbutil.cpp.

72{
73 FxUsbUrbContext* pContext;
75
76 status = Request->ValidateTarget(Target);
77 if (!NT_SUCCESS(status)) {
79 "FormatUrbRequest: Target %p, Request %p, "
80 "setting target failed, %!STATUS!",
82
83 return status;
84 }
85
86 if (Request->HasContextType(FX_RCT_USB_URB_REQUEST)) {
87 pContext = (FxUsbUrbContext*) Request->GetContext();
88 }
89 else {
90 pContext = new(Target->GetDriverGlobals()) FxUsbUrbContext();
91
92 if (pContext == NULL) {
94 }
95
96 Request->SetContext(pContext);
97 }
98
99 //
100 // Always set the memory after determining the context. This way we can
101 // free a previously referenced memory object if necessary.
102 //
104
105 FxFormatUsbRequest(Request, pContext->m_pUrb, FxUrbType, UsbdHandle);
106
107 return STATUS_SUCCESS;
108}
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
@ FX_RCT_USB_URB_REQUEST
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
virtual VOID StoreAndReferenceMemory(__in FxRequestBuffer *Buffer)
Definition: fxusbpipe.cpp:937
Definition: ps.c:97
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID FxFormatUsbRequest(__in FxRequestBase *Request, __in PURB Urb, __in FX_URB_TYPE FxUrbType, __drv_when(FxUrbType==FxUrbTypeUsbdAllocated, __in) __drv_when(FxUrbType !=FxUrbTypeUsbdAllocated, __in_opt) USBD_HANDLE UsbdHandle)
Definition: usbutil.cpp:29
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306

Referenced by __in_xcount().

◆ FxFormatUsbRequest()

VOID FxFormatUsbRequest ( __in FxRequestBase Request,
__in PURB  Urb,
__in FX_URB_TYPE  FxUrbType,
__drv_when(FxUrbType==FxUrbTypeUsbdAllocated, __in) __drv_when(FxUrbType !=FxUrbTypeUsbdAllocated, __in_opt) USBD_HANDLE  UsbdHandle 
)

Definition at line 29 of file usbutil.cpp.

37{
38 FxIrp* irp;
39
40 ASSERT(Urb->UrbHeader.Length >= sizeof(_URB_HEADER));
41
42 irp = Request->GetSubmitFxIrp();
46
47
48
49
50
51 if (FxUrbType == FxUrbTypeUsbdAllocated) {
53 }
54 else {
56 }
57
58 Request->VerifierSetFormatted();
59}
Definition: fxirp.hpp:28
VOID SetMajorFunction(__in UCHAR MajorFunction)
Definition: fxirpum.cpp:905
VOID SetParameterIoctlCode(__in ULONG DeviceIoControlCode)
Definition: fxirpum.cpp:1157
PIO_STACK_LOCATION GetNextIrpStackLocation(VOID)
Definition: fxirpum.cpp:387
VOID ClearNextStackLocation(VOID)
Definition: fxirpum.cpp:1581
VOID SetNextStackParameterOthersArgument1(__in PVOID Argument1)
Definition: fxirpum.cpp:1411
FxIrp * irp
@ FxUrbTypeUsbdAllocated
Definition: fxusbdevice.hpp:28
#define ASSERT(a)
Definition: mode.c:44
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
VOID USBD_AssignUrbToIoStackLocation(_In_ USBD_HANDLE USBDHandle, _In_ PIO_STACK_LOCATION IoStackLocation, _In_ PURB Urb)
Definition: usbstubum.cpp:136
#define IRP_MJ_INTERNAL_DEVICE_CONTROL

Referenced by FxUsbDevice::Deconfig(), FxUsbPipe::FormatAbortRequest(), FxUsbDevice::FormatControlRequest(), FxUsbPipe::FormatResetRequest(), FxUsbDevice::FormatStringRequest(), FxUsbPipe::FormatTransferRequest(), FxFormatUrbRequest(), FxUsbDevice::GetString(), FxUsbDevice::InitDevice(), FxUsbDevice::SelectConfig(), and FxUsbInterface::SelectSetting().

◆ FxUsbCreateConfigRequest()

PURB FxUsbCreateConfigRequest ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PUSB_CONFIGURATION_DESCRIPTOR  ConfigDesc,
__in PUSBD_INTERFACE_LIST_ENTRY  InterfaceList,
__in ULONG  DefaultMaxPacketSize 
)

Definition at line 364 of file usbutil.cpp.

370{
371 PURB urb;
373 USHORT size;
374
375 //
376 // Our mission here is to construct a URB of the proper
377 // size and format for a select_configuration request.
378 //
379 // This function uses the configuration descriptor as a
380 // reference and builds a URB with interface_information
381 // structures for each interface requested in the interface
382 // list passed in
383 //
384 // NOTE: the config descriptor may contain interfaces that
385 // the caller does not specify in the list -- in this case
386 // the other interfaces will be ignored.
387 //
388
389 //
390 // First figure out how many interfaces we are dealing with
391 //
393
394 //
395 // For a multiple interface configuration, GET_SELECT_CONFIGURATION_REQUEST_SIZE
396 // doesn't work as expected. This is because it subtracts one from totalPipes
397 // to compensate for the embedded USBD_PIPE_INFORMATION in USBD_INTERFACE_INFORMATION.
398 // A multiple interface device will have more then one embedded
399 // USBD_PIPE_INFORMATION in its configuration request and any of these interfaces
400 // might not have any pipes on them.
401 //
402 // To fix, just iterate and compute the size incrementally.
403 //
406
407 while (pList->InterfaceDescriptor != NULL) {
409
410 status = RtlUShortAdd(size,
412 pList->InterfaceDescriptor->bNumEndpoints),
413 &size);
414 if (!NT_SUCCESS(status)) {
416 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
417 "InterfaceList %p, NumEndPoints 0x%x, "
418 "Integer overflow while calculating interface size, %!STATUS!",
420 pList->InterfaceDescriptor->bNumEndpoints,
421 status);
422 return NULL;
423 }
424 pList++;
425 }
426 }
427 else {
429 }
430
431 //
432 // Make sure we are dealing with a value that fits into a USHORT
433 //
434 ASSERT(size <= 0xFFFF);
435
436 urb = (PURB) FxPoolAllocate(FxDriverGlobals, NonPagedPool, size);
437
438 if (urb != NULL) {
439 PUCHAR pCur;
440
441 //
442 // now all we have to do is initialize the urb
443 //
444 RtlZeroMemory(urb, size);
445
447
448 pCur = (PUCHAR) &urb->UrbSelectConfiguration.Interface;
449 while (pList->InterfaceDescriptor != NULL) {
450 PUSB_INTERFACE_DESCRIPTOR pInterfaceDesc;
451 PUSBD_INTERFACE_INFORMATION pInterfaceInfo;
452
453 pInterfaceDesc = pList->InterfaceDescriptor;
454
455 pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION) pCur;
456#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "Esp:675");
457 pInterfaceInfo->InterfaceNumber = pInterfaceDesc->bInterfaceNumber;
458 pInterfaceInfo->AlternateSetting = pInterfaceDesc->bAlternateSetting;
459 pInterfaceInfo->NumberOfPipes = pInterfaceDesc->bNumEndpoints;
460 pInterfaceInfo->Length = (USHORT)
461 GET_USBD_INTERFACE_SIZE(pInterfaceDesc->bNumEndpoints);
462
463 for (LONG j = 0; j < pInterfaceDesc->bNumEndpoints; j++) {
464 pInterfaceInfo->Pipes[j].PipeFlags = 0;
465 pInterfaceInfo->Pipes[j].MaximumTransferSize = DefaultMaxPacketSize;
466 }
467
468 ASSERT(pCur + pInterfaceInfo->Length <= ((PUCHAR) urb) + size);
469
470 pList->Interface = pInterfaceInfo;
471
472 pList++;
473 pCur += pInterfaceInfo->Length;
474 }
475
476 urb->UrbHeader.Length = size;
478 urb->UrbSelectConfiguration.ConfigurationDescriptor = ConfigDesc;
479 }
480
481 return urb;
482}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
#define NonPagedPool
Definition: env_spec_w32.h:307
FxChildList * pList
SINGLE_LIST_ENTRY * pCur
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: usb.h:529
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
struct _URB_HEADER UrbHeader
Definition: usb.h:531
USBD_PIPE_INFORMATION Pipes[1]
Definition: usb.h:286
Definition: usbdlib.h:7
ULONG MaximumTransferSize
Definition: usb.h:265
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
struct _URB * PURB
#define URB_FUNCTION_SELECT_CONFIGURATION
Definition: usb.h:86
#define GET_USBD_INTERFACE_SIZE(numEndpoints)
Definition: usbdlib.h:121
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
Definition: usbdlib.h:181
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2334

Referenced by FxUsbDevice::SelectConfigDescriptor(), FxUsbDevice::SelectConfigInterfaces(), FxUsbDevice::SelectConfigMulti(), and FxUsbDevice::SelectConfigSingle().

◆ FxUsbFindDescriptorType()

PUSB_COMMON_DESCRIPTOR FxUsbFindDescriptorType ( __in PVOID  Buffer,
__in size_t  BufferLength,
__in PVOID  Start,
__in LONG  DescriptorType 
)

Definition at line 174 of file usbutil.cpp.

180{
182 PUCHAR pCur, pEnd;
183
184 pCur = (PUCHAR) Start;
185 pEnd = ((PUCHAR) Buffer) + BufferLength;
186
187 while (pCur < pEnd) {
188 //
189 // Check to see if the current point is the desired descriptor type
190 //
192
193 if (descriptor->bDescriptorType == DescriptorType) {
194 return descriptor;
195 }
196
197 pCur += descriptor->bLength;
198 }
199
200 //
201 // Iterated to the end and found nothing
202 //
203 return NULL;
204}
descriptor
Definition: scsi.h:3951
struct _USB_COMMON_DESCRIPTOR * PUSB_COMMON_DESCRIPTOR
_In_ ULONG _In_ PVOID _In_ LONG DescriptorType
Definition: usbdlib.h:160
@ Start
Definition: partlist.h:33
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

Referenced by FxUsbDevice::CreateInterfaces(), FxUsbInterface::CreateSettings(), FxUsbParseConfigurationDescriptor(), and FxUsbValidateDescriptorType().

◆ FxUsbParseConfigurationDescriptor()

PUSB_INTERFACE_DESCRIPTOR FxUsbParseConfigurationDescriptor ( __in PUSB_CONFIGURATION_DESCRIPTOR  ConfigDesc,
__in UCHAR  InterfaceNumber = -1,
__in UCHAR  AlternateSetting = 1 
)

Definition at line 307 of file usbutil.cpp.

312{
313 PUSB_INTERFACE_DESCRIPTOR found, usbInterface;
314 PVOID pStart;
315
316 found = NULL,
317
318 ASSERT(ConfigDesc->bDescriptorType == USB_CONFIGURATION_DESCRIPTOR_TYPE);
319
320 //
321 // Walk the table of descriptors looking for an interface descriptor with
322 // parameters matching those passed in.
323 //
324 pStart = ConfigDesc;
325
326 do {
327 //
328 // Search for descriptor type 'interface'
329 //
330 usbInterface = (PUSB_INTERFACE_DESCRIPTOR)
331 FxUsbFindDescriptorType(ConfigDesc,
332 ConfigDesc->wTotalLength,
333 pStart,
335
336 //
337 // Check to see if have a matching descriptor by eliminating mismatches
338 //
339 if (usbInterface != NULL) {
340 found = usbInterface;
341
342 if (InterfaceNumber != -1 &&
343 usbInterface->bInterfaceNumber != InterfaceNumber) {
344 found = NULL;
345 }
346
347 if (AlternateSetting != -1 &&
348 usbInterface->bAlternateSetting != AlternateSetting) {
349 found = NULL;
350 }
351
352 pStart = ((PUCHAR)usbInterface) + usbInterface->bLength;
353 }
354
355 if (found != NULL) {
356 break;
357 }
358 } while (usbInterface!= NULL);
359
360 return found;
361}
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
struct _USB_INTERFACE_DESCRIPTOR * PUSB_INTERFACE_DESCRIPTOR
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
_In_ PVOID _In_ LONG _In_ LONG AlternateSetting
Definition: usbdlib.h:170
_In_ PVOID _In_ LONG InterfaceNumber
Definition: usbdlib.h:169
PUSB_COMMON_DESCRIPTOR FxUsbFindDescriptorType(__in PVOID Buffer, __in size_t BufferLength, __in PVOID Start, __in LONG DescriptorType)
Definition: usbutil.cpp:174

Referenced by FxUsbDevice::SelectConfigMulti().

◆ FxUsbUmFormatRequest()

VOID FxUsbUmFormatRequest ( __in FxRequestBase Request,
__in_xcount(Urb->Length) PUMURB_HEADER  Urb,
__in IWudfFile *  HostFile,
__in BOOLEAN  Reuse = FALSE 
)

Definition at line 486 of file usbutil.cpp.

511{
512 FX_VERIFY(INTERNAL, CHECK_NOT_NULL(Request));
513 FX_VERIFY(INTERNAL, CHECK_NOT_NULL(Urb));
514 FX_VERIFY(INTERNAL, CHECK_TODO(Urb->Length >= sizeof(_UMURB_HEADER)));
515 FX_VERIFY(INTERNAL, CHECK_NOT_NULL(HostFile));
516
517 IWudfIoIrp* pIoIrp = NULL;
518 IWudfIrp* pIrp = Request->GetSubmitIrp();
519
520 if (Reuse) {
521 //
522 // This allows us to use the same FxSyncRequest
523 // stack object multiple times.
524 //
525 Request->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
526 Request->ClearFieldsForReuse();
527 }
528
529 HRESULT hrQI = pIrp->QueryInterface(IID_IWudfIoIrp, (PVOID*)&pIoIrp);
530 FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pIoIrp));
531
532 pIoIrp->SetTypeForNextStackLocation(UMINT::WdfRequestInternalIoctl);
533
534
535
536
537 pIoIrp->SetDeviceIoControlParametersForNextStackLocation(IOCTL_INETRNAL_USB_SUBMIT_UMURB,
538 0,
539 0);
540
541 pIoIrp->SetOtherParametersForNextStackLocation((PVOID*)&Urb,
542 NULL,
543 NULL,
544 NULL);
545
546 pIoIrp->SetFileForNextIrpStackLocation(HostFile);
547
548 //
549 // Release reference taken by QI
550 //
551 SAFE_RELEASE(pIoIrp);
552 Request->VerifierSetFormatted();
553}
VOID Reuse(__in NTSTATUS Status=STATUS_SUCCESS)
Definition: fxirpum.cpp:661
FX_VERIFY(INTERNAL, CHECK_NOT_NULL(LoaderInterface->pIWudfHost))
HRESULT hrQI
Definition: framework.cpp:106
FxIrp * pIrp
return pRequest Reuse(ReuseParams)
#define IOCTL_INETRNAL_USB_SUBMIT_UMURB
Definition: umusb.h:259
#define SAFE_RELEASE(p)

Referenced by FxUsbPipe::FormatAbortRequest(), FxUsbPipe::FormatResetRequest(), and FxUsbDevice::SendSyncUmUrb().

◆ FxUsbUmInitControlTransferUrb()

VOID FxUsbUmInitControlTransferUrb ( __inout PUMURB  UmUrb,
__in WINUSB_INTERFACE_HANDLE  WinUsbHandle,
__in ULONG  BufferLength,
__in PVOID  Buffer 
)

Definition at line 578 of file usbutil.cpp.

584{
585 RtlZeroMemory(UmUrb, sizeof(UMURB));
586
587 UmUrb->UmUrbControlTransfer.Hdr.InterfaceHandle = WinUsbHandle;
588 UmUrb->UmUrbControlTransfer.Hdr.Function = UMURB_FUNCTION_CONTROL_TRANSFER;
589 UmUrb->UmUrbControlTransfer.Hdr.Length = sizeof(_UMURB_CONTROL_TRANSFER);
590
591 UmUrb->UmUrbControlTransfer.TransferBufferLength = BufferLength;
592 UmUrb->UmUrbControlTransfer.TransferBuffer = Buffer;
593}
Definition: umusb.h:173
#define UMURB_FUNCTION_CONTROL_TRANSFER
Definition: umusb.h:16

◆ FxUsbUmInitDescriptorUrb()

VOID FxUsbUmInitDescriptorUrb ( __inout PUMURB  UmUrb,
__in WINUSB_INTERFACE_HANDLE  WinUsbHandle,
__in UCHAR  DescriptorType,
__in ULONG  BufferLength,
__in PVOID  Buffer 
)

Definition at line 556 of file usbutil.cpp.

563{
564 RtlZeroMemory(UmUrb, sizeof(UMURB));
565
566 UmUrb->UmUrbDescriptorRequest.Hdr.InterfaceHandle = WinUsbHandle;
567 UmUrb->UmUrbDescriptorRequest.Hdr.Function = UMURB_FUNCTION_GET_DESCRIPTOR;
568 UmUrb->UmUrbDescriptorRequest.Hdr.Length = sizeof(_UMURB_DESCRIPTOR_REQUEST);
569
570 UmUrb->UmUrbDescriptorRequest.DescriptorType = DescriptorType;
571 UmUrb->UmUrbDescriptorRequest.Index = 0;
572 UmUrb->UmUrbDescriptorRequest.LanguageID = 0;
573 UmUrb->UmUrbDescriptorRequest.BufferLength = BufferLength;
574 UmUrb->UmUrbDescriptorRequest.Buffer = Buffer;
575}
#define UMURB_FUNCTION_GET_DESCRIPTOR
Definition: umusb.h:56

◆ FxUsbUmInitInformationUrb()

VOID FxUsbUmInitInformationUrb ( __inout PUMURB  UmUrb,
__in WINUSB_INTERFACE_HANDLE  WinUsbHandle,
__in ULONG  BufferLength,
__in PVOID  Buffer 
)

Definition at line 596 of file usbutil.cpp.

602{
603 RtlZeroMemory(UmUrb, sizeof(UMURB));
604
605 UmUrb->UmUrbDeviceInformation.Hdr.InterfaceHandle = WinUsbHandle;
606 UmUrb->UmUrbDeviceInformation.Hdr.Function = UMURB_FUNCTION_GET_DEVICE_INFORMATION;
607 UmUrb->UmUrbDeviceInformation.Hdr.Length = sizeof(_UMURB_DEVICE_INFORMATION);
608
609 UmUrb->UmUrbDeviceInformation.InformationType = DEVICE_SPEED;
610 UmUrb->UmUrbDeviceInformation.BufferLength = BufferLength;
611 UmUrb->UmUrbDeviceInformation.Buffer = Buffer;
612}
#define UMURB_FUNCTION_GET_DEVICE_INFORMATION
Definition: umusb.h:55

◆ FxUsbValidateConfigDescriptorHeaders()

NTSTATUS FxUsbValidateConfigDescriptorHeaders ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PUSB_CONFIGURATION_DESCRIPTOR  ConfigDescriptor,
__in size_t  ConfigDescriptorLength 
)

Definition at line 111 of file usbutil.cpp.

116{
117 PUCHAR pCur, pEnd;
118
121
122 while (pCur < pEnd) {
124
125 //
126 // Make sure we can safely deref bLength, bDescriptorType
127 //
128 if (pCur + sizeof(USB_COMMON_DESCRIPTOR) > pEnd) {
130 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
131 "USB Configuration packet contains bad data, expected "
132 "at least %d remaining bytes in config descriptor at "
133 "offset %I64d, total size is %I64d",
136 );
138 }
139
140 //
141 // Make sure bLength is within bounds of the config descriptor
142 //
143 if ((pCur + pDescriptor->bLength) > pEnd) {
145 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
146 "USB Configuration packet contains bad data, descriptor at offset "
147 "%I64d specified bLength %d, only %I64d bytes remaining in config "
148 "descriptor, total size is %I64d",
149 pCur-(PUCHAR)ConfigDescriptor, pDescriptor->bLength, pEnd-pCur,
151 );
153 }
154
155 if (pDescriptor->bLength == 0) {
157 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
158 "USB Configuration packet contains bad data, descriptor at offset "
159 "%I64d contains bLength == 0, this is due to a broken device or driver",
161 );
163 }
164
165
166 pCur += pDescriptor->bLength;
167 }
168
169 return STATUS_SUCCESS;
170}
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID ConfigDescriptor
Definition: wdfusb.h:1036
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID _Inout_ PUSHORT ConfigDescriptorLength
Definition: wdfusb.h:1040

Referenced by FxUsbDevice::CreateInterfaces().

◆ FxUsbValidateDescriptorType()

NTSTATUS FxUsbValidateDescriptorType ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PUSB_CONFIGURATION_DESCRIPTOR  ConfigDescriptor,
__in PVOID  Start,
__in PVOID  End,
__in LONG  DescriptorType,
__in size_t  SizeToValidate,
__in FxUsbValidateDescriptorOp  Op,
__in ULONG  MaximumNumDescriptorsToValidate 
)

Definition at line 207 of file usbutil.cpp.

240{
241 PUSB_COMMON_DESCRIPTOR pDescriptor = NULL;
242 PVOID pCur = Start;
243 ULONG i = 1;
244
245 while ((pDescriptor = FxUsbFindDescriptorType(Start,
246 (PUCHAR)End-(PUCHAR)Start,
247 pCur,
249 )) != NULL) {
250 //
251 // Make sure bLength is the correct value
252 //
254 if (pDescriptor->bLength != SizeToValidate) {
256 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
257 "USB Configuration packet contains bad data, found descriptor "
258 "#%d of type %d at offset %I64d, expected bLength of %I64d, found %d",
259 i, DescriptorType, ((PUCHAR)pDescriptor)-((PUCHAR)ConfigDescriptor),
260 SizeToValidate, pDescriptor->bLength
261 );
263 }
264 }
265 else if (Op == FxUsbValidateDescriptorOpAtLeast) {
266 if (pDescriptor->bLength < SizeToValidate) {
268 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
269 "USB Configuration packet contains bad data, found descriptor "
270 "#%d of type %d at offset %I64d, expected minimum bLength of %I64d, "
271 "found %d",
272 i, DescriptorType, ((PUCHAR)pDescriptor)-((PUCHAR)ConfigDescriptor),
273 SizeToValidate, pDescriptor->bLength
274 );
276 }
277 }
278
279 //
280 // No need to validate WDF_PTR_ADD_OFFSET(pDescriptor, pDescriptor->bLength) > End
281 // because FxUsbValidateConfigDescriptorHeaders already has done so. End is either
282 // 1) == end of the config descriptor, in which case FxUsbValidateConfigDescriptorHeaders
283 // directly validated bLength
284 // or
285 // 2) End is somewere in the middle of the config descriptor and ASSUMED to be the start
286 // of a common descriptor header. To find that value of End, we would have had to use
287 // pDescriptor->bLength to get to End, we would not overrun
288 //
289
290 //
291 // i is one based, so the current value is Nth descriptor we have validated. If
292 // the caller wants to limit the number of descriptors validated by indicating a
293 // Max > 0, stop with success if the condition is met.
294 //
295 if (MaximumNumDescriptorsToValidate > 0 && i == MaximumNumDescriptorsToValidate) {
296 break;
297 }
298
299 pCur = WDF_PTR_ADD_OFFSET(pDescriptor, pDescriptor->bLength);
300 i++;
301 }
302
303 return STATUS_SUCCESS;
304}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t ULONG
Definition: typedefs.h:59
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144

Referenced by FxUsbDevice::CreateInterfaces(), and FxUsbInterface::CreateSettings().