ReactOS 0.4.16-dev-1946-g52006dd
usbutil.cpp File Reference
#include "fxusbpch.hpp"
Include dependency graph for usbutil.cpp:

Go to the source code of this file.

Functions

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)
 
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)
 
PUSB_INTERFACE_DESCRIPTOR FxUsbParseConfigurationDescriptor (__in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in UCHAR InterfaceNumber, __in UCHAR AlternateSetting)
 
PURB FxUsbCreateConfigRequest (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in PUSBD_INTERFACE_LIST_ENTRY InterfaceList, __in ULONG DefaultMaxPacketSize)
 
VOID FxUsbUmFormatRequest (__in FxRequestBase *Request, __in_xcount(Urb->Length) PUMURB_HEADER Urb, __in IWudfFile *HostFile, __in BOOLEAN Reuse)
 
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)
 

Function Documentation

◆ 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 64 of file usbutil.cpp.

74{
75 FxUsbUrbContext* pContext;
77
78 status = Request->ValidateTarget(Target);
79 if (!NT_SUCCESS(status)) {
81 "FormatUrbRequest: Target %p, Request %p, "
82 "setting target failed, %!STATUS!",
84
85 return status;
86 }
87
88 if (Request->HasContextType(FX_RCT_USB_URB_REQUEST)) {
89 pContext = (FxUsbUrbContext*) Request->GetContext();
90 }
91 else {
92 pContext = new(Target->GetDriverGlobals()) FxUsbUrbContext();
93
94 if (pContext == NULL) {
96 }
97
98 Request->SetContext(pContext);
99 }
100
101 //
102 // Always set the memory after determining the context. This way we can
103 // free a previously referenced memory object if necessary.
104 //
106
107 FxFormatUsbRequest(Request, pContext->m_pUrb, FxUrbType, UsbdHandle);
108
109 return STATUS_SUCCESS;
110}
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:33
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:939
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:31
_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 31 of file usbutil.cpp.

39{
40 FxIrp* irp;
41
42 ASSERT(Urb->UrbHeader.Length >= sizeof(_URB_HEADER));
43
44 irp = Request->GetSubmitFxIrp();
48
49
50
51
52
53 if (FxUrbType == FxUrbTypeUsbdAllocated) {
55 }
56 else {
58 }
59
60 Request->VerifierSetFormatted();
61}
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
VOID USBD_AssignUrbToIoStackLocation(_In_ USBD_HANDLE USBDHandle, _In_ PIO_STACK_LOCATION IoStackLocation, _In_ PURB Urb)
Definition: usbdex.c:28
_In_ PIO_STACK_LOCATION _In_ PURB Urb
Definition: usbdlib.h:267
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#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 366 of file usbutil.cpp.

372{
373 PURB urb;
375 USHORT size;
376
377 //
378 // Our mission here is to construct a URB of the proper
379 // size and format for a select_configuration request.
380 //
381 // This function uses the configuration descriptor as a
382 // reference and builds a URB with interface_information
383 // structures for each interface requested in the interface
384 // list passed in
385 //
386 // NOTE: the config descriptor may contain interfaces that
387 // the caller does not specify in the list -- in this case
388 // the other interfaces will be ignored.
389 //
390
391 //
392 // First figure out how many interfaces we are dealing with
393 //
395
396 //
397 // For a multiple interface configuration, GET_SELECT_CONFIGURATION_REQUEST_SIZE
398 // doesn't work as expected. This is because it subtracts one from totalPipes
399 // to compensate for the embedded USBD_PIPE_INFORMATION in USBD_INTERFACE_INFORMATION.
400 // A multiple interface device will have more then one embedded
401 // USBD_PIPE_INFORMATION in its configuration request and any of these interfaces
402 // might not have any pipes on them.
403 //
404 // To fix, just iterate and compute the size incrementally.
405 //
408
409 while (pList->InterfaceDescriptor != NULL) {
411
412 status = RtlUShortAdd(size,
414 pList->InterfaceDescriptor->bNumEndpoints),
415 &size);
416 if (!NT_SUCCESS(status)) {
418 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
419 "InterfaceList %p, NumEndPoints 0x%x, "
420 "Integer overflow while calculating interface size, %!STATUS!",
422 pList->InterfaceDescriptor->bNumEndpoints,
423 status);
424 return NULL;
425 }
426 pList++;
427 }
428 }
429 else {
431 }
432
433 //
434 // Make sure we are dealing with a value that fits into a USHORT
435 //
436 ASSERT(size <= 0xFFFF);
437
438 urb = (PURB) FxPoolAllocate(FxDriverGlobals, NonPagedPool, size);
439
440 if (urb != NULL) {
441 PUCHAR pCur;
442
443 //
444 // now all we have to do is initialize the urb
445 //
446 RtlZeroMemory(urb, size);
447
449
450 pCur = (PUCHAR) &urb->UrbSelectConfiguration.Interface;
451 while (pList->InterfaceDescriptor != NULL) {
452 PUSB_INTERFACE_DESCRIPTOR pInterfaceDesc;
453 PUSBD_INTERFACE_INFORMATION pInterfaceInfo;
454
455 pInterfaceDesc = pList->InterfaceDescriptor;
456
457 pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION) pCur;
458#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "Esp:675");
459 pInterfaceInfo->InterfaceNumber = pInterfaceDesc->bInterfaceNumber;
460 pInterfaceInfo->AlternateSetting = pInterfaceDesc->bAlternateSetting;
461 pInterfaceInfo->NumberOfPipes = pInterfaceDesc->bNumEndpoints;
462 pInterfaceInfo->Length = (USHORT)
463 GET_USBD_INTERFACE_SIZE(pInterfaceDesc->bNumEndpoints);
464
465 for (LONG j = 0; j < pInterfaceDesc->bNumEndpoints; j++) {
466 pInterfaceInfo->Pipes[j].PipeFlags = 0;
467 pInterfaceInfo->Pipes[j].MaximumTransferSize = DefaultMaxPacketSize;
468 }
469
470 ASSERT(pCur + pInterfaceInfo->Length <= ((PUCHAR) urb) + size);
471
472 pList->Interface = pInterfaceInfo;
473
474 pList++;
475 pCur += pInterfaceInfo->Length;
476 }
477
478 urb->UrbHeader.Length = size;
480 urb->UrbSelectConfiguration.ConfigurationDescriptor = ConfigDesc;
481 }
482
483 return urb;
484}
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 176 of file usbutil.cpp.

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

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

◆ FxUsbParseConfigurationDescriptor()

PUSB_INTERFACE_DESCRIPTOR FxUsbParseConfigurationDescriptor ( __in PUSB_CONFIGURATION_DESCRIPTOR  ConfigDesc,
__in UCHAR  InterfaceNumber,
__in UCHAR  AlternateSetting 
)

Definition at line 309 of file usbutil.cpp.

314{
315 PUSB_INTERFACE_DESCRIPTOR found, usbInterface;
316 PVOID pStart;
317
318 found = NULL,
319
320 ASSERT(ConfigDesc->bDescriptorType == USB_CONFIGURATION_DESCRIPTOR_TYPE);
321
322 //
323 // Walk the table of descriptors looking for an interface descriptor with
324 // parameters matching those passed in.
325 //
326 pStart = ConfigDesc;
327
328 do {
329 //
330 // Search for descriptor type 'interface'
331 //
332 usbInterface = (PUSB_INTERFACE_DESCRIPTOR)
333 FxUsbFindDescriptorType(ConfigDesc,
334 ConfigDesc->wTotalLength,
335 pStart,
337
338 //
339 // Check to see if have a matching descriptor by eliminating mismatches
340 //
341 if (usbInterface != NULL) {
342 found = usbInterface;
343
344 if (InterfaceNumber != -1 &&
345 usbInterface->bInterfaceNumber != InterfaceNumber) {
346 found = NULL;
347 }
348
349 if (AlternateSetting != -1 &&
350 usbInterface->bAlternateSetting != AlternateSetting) {
351 found = NULL;
352 }
353
354 pStart = ((PUCHAR)usbInterface) + usbInterface->bLength;
355 }
356
357 if (found != NULL) {
358 break;
359 }
360 } while (usbInterface!= NULL);
361
362 return found;
363}
#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:176

Referenced by FxUsbDevice::SelectConfigMulti().

◆ FxUsbUmFormatRequest()

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

Definition at line 488 of file usbutil.cpp.

513{
514 FX_VERIFY(INTERNAL, CHECK_NOT_NULL(Request));
515 FX_VERIFY(INTERNAL, CHECK_NOT_NULL(Urb));
516 FX_VERIFY(INTERNAL, CHECK_TODO(Urb->Length >= sizeof(_UMURB_HEADER)));
517 FX_VERIFY(INTERNAL, CHECK_NOT_NULL(HostFile));
518
519 IWudfIoIrp* pIoIrp = NULL;
520 IWudfIrp* pIrp = Request->GetSubmitIrp();
521
522 if (Reuse) {
523 //
524 // This allows us to use the same FxSyncRequest
525 // stack object multiple times.
526 //
527 Request->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
528 Request->ClearFieldsForReuse();
529 }
530
531 HRESULT hrQI = pIrp->QueryInterface(IID_IWudfIoIrp, (PVOID*)&pIoIrp);
532 FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pIoIrp));
533
534 pIoIrp->SetTypeForNextStackLocation(UMINT::WdfRequestInternalIoctl);
535
536
537
538
539 pIoIrp->SetDeviceIoControlParametersForNextStackLocation(IOCTL_INETRNAL_USB_SUBMIT_UMURB,
540 0,
541 0);
542
543 pIoIrp->SetOtherParametersForNextStackLocation((PVOID*)&Urb,
544 NULL,
545 NULL,
546 NULL);
547
548 pIoIrp->SetFileForNextIrpStackLocation(HostFile);
549
550 //
551 // Release reference taken by QI
552 //
553 SAFE_RELEASE(pIoIrp);
554 Request->VerifierSetFormatted();
555}
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 580 of file usbutil.cpp.

586{
587 RtlZeroMemory(UmUrb, sizeof(UMURB));
588
589 UmUrb->UmUrbControlTransfer.Hdr.InterfaceHandle = WinUsbHandle;
590 UmUrb->UmUrbControlTransfer.Hdr.Function = UMURB_FUNCTION_CONTROL_TRANSFER;
591 UmUrb->UmUrbControlTransfer.Hdr.Length = sizeof(_UMURB_CONTROL_TRANSFER);
592
593 UmUrb->UmUrbControlTransfer.TransferBufferLength = BufferLength;
594 UmUrb->UmUrbControlTransfer.TransferBuffer = Buffer;
595}
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 558 of file usbutil.cpp.

565{
566 RtlZeroMemory(UmUrb, sizeof(UMURB));
567
568 UmUrb->UmUrbDescriptorRequest.Hdr.InterfaceHandle = WinUsbHandle;
569 UmUrb->UmUrbDescriptorRequest.Hdr.Function = UMURB_FUNCTION_GET_DESCRIPTOR;
570 UmUrb->UmUrbDescriptorRequest.Hdr.Length = sizeof(_UMURB_DESCRIPTOR_REQUEST);
571
572 UmUrb->UmUrbDescriptorRequest.DescriptorType = DescriptorType;
573 UmUrb->UmUrbDescriptorRequest.Index = 0;
574 UmUrb->UmUrbDescriptorRequest.LanguageID = 0;
575 UmUrb->UmUrbDescriptorRequest.BufferLength = BufferLength;
576 UmUrb->UmUrbDescriptorRequest.Buffer = Buffer;
577}
#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 598 of file usbutil.cpp.

604{
605 RtlZeroMemory(UmUrb, sizeof(UMURB));
606
607 UmUrb->UmUrbDeviceInformation.Hdr.InterfaceHandle = WinUsbHandle;
608 UmUrb->UmUrbDeviceInformation.Hdr.Function = UMURB_FUNCTION_GET_DEVICE_INFORMATION;
609 UmUrb->UmUrbDeviceInformation.Hdr.Length = sizeof(_UMURB_DEVICE_INFORMATION);
610
611 UmUrb->UmUrbDeviceInformation.InformationType = DEVICE_SPEED;
612 UmUrb->UmUrbDeviceInformation.BufferLength = BufferLength;
613 UmUrb->UmUrbDeviceInformation.Buffer = Buffer;
614}
#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 113 of file usbutil.cpp.

118{
119 PUCHAR pCur, pEnd;
120
123
124 while (pCur < pEnd) {
126
127 //
128 // Make sure we can safely deref bLength, bDescriptorType
129 //
130 if (pCur + sizeof(USB_COMMON_DESCRIPTOR) > pEnd) {
132 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
133 "USB Configuration packet contains bad data, expected "
134 "at least %d remaining bytes in config descriptor at "
135 "offset %I64d, total size is %I64d",
138 );
140 }
141
142 //
143 // Make sure bLength is within bounds of the config descriptor
144 //
145 if ((pCur + pDescriptor->bLength) > pEnd) {
147 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
148 "USB Configuration packet contains bad data, descriptor at offset "
149 "%I64d specified bLength %d, only %I64d bytes remaining in config "
150 "descriptor, total size is %I64d",
151 pCur-(PUCHAR)ConfigDescriptor, pDescriptor->bLength, pEnd-pCur,
153 );
155 }
156
157 if (pDescriptor->bLength == 0) {
159 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIOTARGET,
160 "USB Configuration packet contains bad data, descriptor at offset "
161 "%I64d contains bLength == 0, this is due to a broken device or driver",
163 );
165 }
166
167
168 pCur += pDescriptor->bLength;
169 }
170
171 return STATUS_SUCCESS;
172}
#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 209 of file usbutil.cpp.

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

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