ReactOS 0.4.16-dev-1946-g52006dd
fxusbdevicekm.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxUsbDeviceKm.cpp
8
9Abstract:
10
11Author:
12
13Environment:
14
15 kernel mode only
16
17Revision History:
18
19--*/
20
21extern "C" {
22#include <initguid.h>
23}
24
25#include "../fxusbpch.hpp"
26
27
28extern "C" {
29#if defined(EVENT_TRACING)
30#include "FxUsbDeviceKm.tmh"
31#endif
32}
33
34
35
36
37
38
39
40#define UCHAR_MAX (0xff)
41
42
46 __in ULONG USBDClientContractVersionForWdfClient
47 )
48{
49 URB urb;
50 FxSyncRequest request(GetDriverGlobals(), NULL);
53 ULONG size;
54 ULONG paddedSize;
55
56 RtlZeroMemory(&urb, sizeof(urb));
57
58 if (USBDClientContractVersionForWdfClient != USBD_CLIENT_CONTRACT_VERSION_INVALID) {
59
60 //
61 // Register with USBDEX.lib
62 //
65 USBDClientContractVersionForWdfClient,
68
69 if (!NT_SUCCESS(status)) {
72 "USBD_CreateHandle failed, %!STATUS!", status);
73 goto Done;
74 }
75
77 }
78
79 status = request.m_TrueRequest->ValidateTarget(this);
80 if (!NT_SUCCESS(status)) {
81 goto Done;
82 }
83
87 0,
88 0,
90 NULL,
91 sizeof(m_DeviceDescriptor),
92 NULL);
93
94 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
95
98
99 status = SubmitSync(request.m_TrueRequest, &options);
100 if (!NT_SUCCESS(status)) {
103 "Could not retrieve device descriptor, %!STATUS!", status);
104 goto Done;
105 }
106
107 //
108 // After successfully completing any default control URB, USBD/usbport fills
109 // in the PipeHandle field of the URB (it is the same offset in every URB,
110 // which this CASSERT verifies. Since USBD_DEFAULT_PIPE_TRANSFER is not
111 // supported by USBD (it is by USBPORT), this is the prescribed way of getting
112 // the default control pipe so that you can set the PipeHandle field in
113 // _URB_CONTROL_TRANSFER.
114 //
117
119
121
122 RtlZeroMemory(&config, sizeof(config));
123 size = sizeof(config);
124
128 0,
129 0,
130 &config,
131 NULL,
132 size,
133 NULL);
134
135 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
136 request.m_TrueRequest->ClearFieldsForReuse();
137 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
138
139 status = SubmitSync(request.m_TrueRequest, &options);
140 if (!NT_SUCCESS(status)) {
143 "Could not retrieve config descriptor size, %!STATUS!", status);
144 goto Done;
145 }
146 else if (urb.UrbControlDescriptorRequest.TransferBufferLength == 0) {
147 //
148 // Not enough info returned
149 //
151
154 "Could not retrieve config descriptor size, zero bytes transferred, "
155 " %!STATUS!", status);
156
157 goto Done;
158 }
159 else if (config.wTotalLength < size) {
160 //
161 // Not enough info returned
162 //
164
167 "Could not retrieve config descriptor size, config.wTotalLength %d < "
168 "sizeof(config descriptor) (%d), %!STATUS!",
169 config.wTotalLength, size, status);
170
171 goto Done;
172 }
173
174 //
175 // Allocate an additional memory at the end of the buffer so if we
176 // accidentily access fields beyond the end of the buffer we don't crash
177
178 //
179
180
181
182
183
184 size = config.wTotalLength;
185 paddedSize = size + sizeof(USB_DEVICE_DESCRIPTOR);
186
188 FxPoolAllocate(GetDriverGlobals(),
190 paddedSize);
191
192 if (m_ConfigDescriptor == NULL) {
194
197 "Could not allocate %d bytes for config descriptor, %!STATUS!",
198 paddedSize, status);
199
200 goto Done;
201 }
202
204
208 0,
209 0,
211 NULL,
212 size,
213 NULL);
214
215 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
216 request.m_TrueRequest->ClearFieldsForReuse();
217 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
218
219 status = SubmitSync(request.m_TrueRequest, &options);
220 if (!NT_SUCCESS(status)) {
223 "Could not retrieve config descriptor, %!STATUS!", status);
224 goto Done;
225 } else if(m_ConfigDescriptor->wTotalLength != size) {
226 //
227 // Invalid wTotalLength
228 //
232 "Defective USB device reported two different config descriptor "
233 "wTotalLength values: %d and %d, %!STATUS!",
235 goto Done;
236 }
237
238 //
239 // Check to see if we are wait wake capable
240 //
243 }
244
245 //
246 // Check to see if we are self or bus powered
247 //
248 USHORT deviceStatus;
249
252 0,
253 &deviceStatus,
254 NULL,
255 NULL);
256
257 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_SUCCESS);
258 request.m_TrueRequest->ClearFieldsForReuse();
259 FxFormatUsbRequest(request.m_TrueRequest, &urb, FxUrbTypeLegacy, NULL);
260
261 status = SubmitSync(request.m_TrueRequest, &options);
262 if (NT_SUCCESS(status) && (deviceStatus & USB_GETSTATUS_SELF_POWERED)) {
264 }
265
266 //
267 // Revert back to success b/c we don't care if the usb device get status
268 // fails
269 //
271
273
274 RtlZeroMemory(&busIf, sizeof(busIf));
275
276 //
277 // All PNP irps must have this initial status
278 //
279 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_NOT_SUPPORTED);
280 request.m_TrueRequest->ClearFieldsForReuse();
281
283 request.m_TrueRequest->GetSubmitFxIrp()->GetIrp(),
284 &USB_BUS_INTERFACE_USBDI_GUID,
285 (PINTERFACE) &busIf,
286 sizeof(busIf),
288
289 request.m_TrueRequest->VerifierSetFormatted();
290
291 status = SubmitSync(request.m_TrueRequest);
292
293 if (!NT_SUCCESS(status)) {
294 //
295 // Retry with the older interface
296 //
297 RtlZeroMemory(&busIf, sizeof(busIf));
298
299 //
300 // All PNP irps must have this initial status
301 //
302
303 request.m_TrueRequest->GetSubmitFxIrp()->Reuse(STATUS_NOT_SUPPORTED);
304 request.m_TrueRequest->ClearFieldsForReuse();
305
307 request.m_TrueRequest->GetSubmitFxIrp()->GetIrp(),
308 &USB_BUS_INTERFACE_USBDI_GUID,
309 (PINTERFACE) &busIf,
312
313 request.m_TrueRequest->VerifierSetFormatted();
314
315 status = SubmitSync(request.m_TrueRequest);
316 }
317
318 if (NT_SUCCESS(status)) {
319 //
320 // Need to check for NULL b/c we may have only retrieved the V0 interface
321 //
322 if (busIf.IsDeviceHighSpeed != NULL &&
323 busIf.IsDeviceHighSpeed(busIf.BusContext)) {
325 }
326
327 //
328 // Stash these off for later
329 //
333
334 ASSERT(busIf.GetUSBDIVersion != NULL);
335 busIf.GetUSBDIVersion(busIf.BusContext,
338 }
339 else if (status == STATUS_NOT_SUPPORTED) {
340 //
341 // We will only use m_ControlPipe on stacks which do not support
342 // USBD_DEFAULT_PIPE_TRANSFER. If all the QIs failed, then we know
343 // definitively that we are running on USBD and we need m_ControlPipe
344 // to be != NULL for later control transfers
345 //
347
348 m_OnUSBD = TRUE;
349
350 //
351 // The QI failed with not supported, do not return error
352 //
354 }
355 else {
358 "Query Interface for bus returned error, %!STATUS!", status);
359 }
360
361Done:
362
363 return status;
364}
365
373 __in_opt WDFREQUEST Request,
375 )
376{
377 PUSB_STRING_DESCRIPTOR pDescriptor;
384
385 FxSyncRequest request(GetDriverGlobals(), NULL, Request);
386
387 //
388 // FxSyncRequest always succeesds for KM.
389 //
390 status = request.Initialize();
391 if (!NT_SUCCESS(status)) {
393 "Failed to initialize FxSyncRequest");
394 return status;
395 }
396
397 buffer = NULL;
398
399 status = request.m_TrueRequest->ValidateTarget(this);
400 if (!NT_SUCCESS(status)) {
401 goto Done;
402 }
403
404 RtlZeroMemory(&urb, sizeof(urb));
405
406 if (String != NULL) {
407 length = sizeof(USB_STRING_DESCRIPTOR) + (*NumCharacters - 1) * sizeof(WCHAR);
408
409 buffer = FxPoolAllocate(GetDriverGlobals(),
411 length);
412
413 if (buffer == NULL) {
415 goto Done;
416 }
417
419 pDescriptor = (PUSB_STRING_DESCRIPTOR) buffer;
420 }
421 else {
422 RtlZeroMemory(&common, sizeof(common));
423
425 pDescriptor = (PUSB_STRING_DESCRIPTOR) &common;
426 }
427
432 LangID,
433 pDescriptor,
434 NULL,
435 length,
436 NULL);
437
438 if (Options != NULL) {
439 pOptions = Options;
440 }
441 else {
445
446 pOptions = &options;
447 }
448#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "this annotation change in usb.h is communicated to usb team")
449 FxFormatUsbRequest(request.m_TrueRequest, (PURB) &urb, FxUrbTypeLegacy, NULL);
450 status = SubmitSync(request.m_TrueRequest, pOptions);
451
452 if (NT_SUCCESS(status)) {
454
455 //
456 // Make sure we got an even number of bytes and that we got a header
457 //
458 if ((pDescriptor->bLength & 0x1) ||
459 pDescriptor->bLength < sizeof(USB_COMMON_DESCRIPTOR)) {
461 }
462 else {
463 //
464 // bLength is the length of the entire descriptor. Subtract off
465 // the descriptor header and then divide by the size of a WCHAR.
466 //
467 numChars =
468 (pDescriptor->bLength - sizeof(USB_COMMON_DESCRIPTOR)) / sizeof(WCHAR);
469
470 if (String != NULL) {
471 if (*NumCharacters >= numChars) {
472 length = numChars * sizeof(WCHAR);
473 }
474 else {
475 length = *NumCharacters * sizeof(WCHAR);
477 }
478
480 RtlCopyMemory(String, pDescriptor->bString, length);
481 }
482 else {
484 }
485 }
486 }
487
488 if (buffer != NULL) {
490 }
491
492Done:
493
494 return status;
495}
496
501 __in FxRequestBuffer *RequestBuffer,
504 )
505/*++
506
507Routine Description:
508 Formats a request to retrieve a string from a string descriptor
509
510Arguments:
511 Request - request to format
512
513 RequestBuffer - Buffer to be filled in when the request has completed
514
515 StringIndex - index of the string
516
517 LandID - language ID of the string to be retrieved
518
519Return Value:
520 NTSTATUS
521
522 --*/
523{
524 FxUsbDeviceStringContext* pContext;
526 FX_URB_TYPE urbType;
527
528 status = Request->ValidateTarget(this);
529 if (!NT_SUCCESS(status)) {
531 "WDFUSBDEVICE %p, Request %p, setting target failed, "
532 "%!STATUS!", GetHandle(), Request, status);
533
534 return status;
535 }
536
537 if (Request->HasContextType(FX_RCT_USB_STRING_REQUEST)) {
538 pContext = (FxUsbDeviceStringContext*) Request->GetContext();
539 }
540 else {
541
543 pContext = new(GetDriverGlobals()) FxUsbDeviceStringContext(urbType);
544 if (pContext == NULL) {
546 }
547
548 if (urbType == FxUrbTypeUsbdAllocated) {
549 status = pContext->AllocateUrb(m_USBDHandle);
550 if (!NT_SUCCESS(status)) {
552 "FxUsbDeviceStringContext::AllocateUrb failed, %!STATUS!", status);
553 delete pContext;
554 return status;
555 }
556
557 //
558 // Since the AllocateUrb routine calls USBD_xxxUrbAllocate APIs to allocate an Urb, it is
559 // important to release those resorces before the devnode is removed. Those
560 // resoruces are removed at the time Request is disposed.
561 //
562 Request->EnableContextDisposeNotification();
563 }
564
565 Request->SetContext(pContext);
566 }
567
569 RequestBuffer->GetBufferLength());
570 if (!NT_SUCCESS(status)) {
571 return status;
572 }
573
574 pContext->StoreAndReferenceMemory(RequestBuffer);
575 pContext->SetUrbInfo(StringIndex, LangID);
576
577 if (pContext->m_Urb == &pContext->m_UrbLegacy) {
578 urbType = FxUrbTypeLegacy;
579 }
580 else {
581 urbType = FxUrbTypeUsbdAllocated;
582 }
583
584 FxFormatUsbRequest(Request, (PURB)pContext->m_Urb, urbType, m_USBDHandle);
585
586 return STATUS_SUCCESS;
587}
588
594 __in FxRequestBuffer *RequestBuffer
595 )
596{
599 size_t bufferSize;
600 FX_URB_TYPE urbType;
601
602 bufferSize = RequestBuffer->GetBufferLength();
603
604 //
605 // We can only transfer 2 bytes worth of data, so if the buffer is larger,
606 // fail here.
607 //
608 if (bufferSize > 0xFFFF) {
611 "Control transfer buffer is limited to 0xFFFF bytes in size, "
612 "%I64d requested ", bufferSize);
613
615 }
616
617 status = Request->ValidateTarget(this);
618 if (!NT_SUCCESS(status)) {
620 "WDFUSBDEVICE %p, Request %p, setting target failed, "
621 "%!STATUS!", GetHandle(), Request, status);
622
623 return status;
624 }
625
626 if (Request->HasContextType(FX_RCT_USB_CONTROL_REQUEST)) {
627 pContext = (FxUsbDeviceControlContext*) Request->GetContext();
628 }
629 else {
630
632 pContext = new(GetDriverGlobals()) FxUsbDeviceControlContext(urbType);
633 if (pContext == NULL) {
635 }
636
637 if (urbType == FxUrbTypeUsbdAllocated) {
638 status = pContext->AllocateUrb(m_USBDHandle);
639 if (!NT_SUCCESS(status)) {
641 "FxUsbDeviceControlContext::AllocateUrb Failed, %!STATUS!", status);
642
643 delete pContext;
644 return status;
645 }
646 //
647 // Since the AllocateUrb routine calls USBD_xxxUrbAllocate APIs to allocate an Urb, it is
648 // important to release those resorces before the devnode is removed. Those
649 // resoruces are removed at the time Request is disposed.
650 //
651 Request->EnableContextDisposeNotification();
652 }
653
654 Request->SetContext(pContext);
655 }
656
657 if (RequestBuffer->HasMdl()) {
658 PMDL pMdl;
659
660 pMdl = NULL;
661 ASSERT(pContext->m_PartialMdl == NULL);
662
663 status = RequestBuffer->GetOrAllocateMdl(GetDriverGlobals(),
664 &pMdl,
665 &pContext->m_PartialMdl,
666 &pContext->m_UnlockPages,
668
669 if (!NT_SUCCESS(status)) {
670 return status;
671 }
672
673 ASSERT(pMdl != NULL);
674 }
675
676 pContext->StoreAndReferenceMemory(this, RequestBuffer, SetupPacket);
677
678 if (pContext->m_Urb == &pContext->m_UrbLegacy) {
679 urbType = FxUrbTypeLegacy;
680 }
681 else {
682 urbType = FxUrbTypeUsbdAllocated;
683 }
684
685 FxFormatUsbRequest(Request, (PURB)pContext->m_Urb, urbType, m_USBDHandle);
686
687 return STATUS_SUCCESS;
688}
689
690VOID
695 )
696{
698
699 RtlZeroMemory(m_Urb, sizeof(*m_Urb));
700
702 m_Urb->Hdr.Length = sizeof(*m_Urb);
703
705
706 //
707 // Set the values using what is stored in the buffer
708 //
709 Buffer->AssignValues(&m_Urb->TransferBuffer,
712
714 &SetupPacket->Generic.Bytes[0],
715 sizeof(m_Urb->SetupPacket));
716
717 //
718 // also indicate the length of the buffer in the header
719 //
720 ((PWDF_USB_CONTROL_SETUP_PACKET) &m_Urb->SetupPacket[0])->Packet.wLength =
722
723 //
724 // Control transfers are always short OK. USBD_TRANSFER_DIRECTION_IN may
725 // be OR'ed in later.
726 //
728
729 //
730 // Get the direction out of the setup packet
731 //
732 if (SetupPacket->Packet.bm.Request.Dir == BMREQUEST_DEVICE_TO_HOST) {
734 }
735
736 if (Device->OnUSBD()) {
737 m_Urb->PipeHandle = Device->GetControlPipeHandle();
738 }
739 else {
740 //
741 // USBPORT supports this flag
742 //
744 }
745
746 //
747 // If we have built a partial MDL, use that instead. TransferBufferLength
748 // is still valid because the Offsets or length in Buffer will have been
749 // used to create this PartialMdl by the caller.
750 //
751 if (m_PartialMdl != NULL) {
753 }
754}
755
759 __in
761 __in
766 PVOID CapabilityBuffer,
770 )
771{
773
774 if (ResultLength != NULL) {
775 *ResultLength = 0;
776 }
777
778 if (GetUSBDHandle() == NULL) {
780
783 "WDFUSBDEVICE must have been created using WdfUsbTargetDeviceCreateWithParameters, %!STATUS!",
784 status);
785
786 return status;
787 }
788
792 (PUCHAR) CapabilityBuffer,
794
795 if (!NT_SUCCESS(status)) {
798 "Could not retrieve capability %!GUID!, %!STATUS!",
800 goto exit;
801 }
802
803exit:
804 return status;
805}
806
812 )
813/*++
814
815Routine Description:
816 This will configure the single inteface case and pick up the first available
817 setting. If there are multiple settings on a single interface device
818 and the driver wants to pick one then the driver should use the multinterface
819 option to initialize.
820
821 This takes care of the simplest case only. Configuring a multi interface
822 device as a single interface device would be treated as an error. There is
823 duplication of code with the multi case but it is better to keep these two
824 separate especially if more gets added.
825
826Arguments:
827
828
829Return Value:
830 NTSTATUS
831
832 --*/
833{
834 //
835 // The array needs an extra element which is zero'd out to mark the end
836 //
837 USBD_INTERFACE_LIST_ENTRY listEntry[2];
838 PURB urb;
840
841 RtlZeroMemory(&Params->Types.SingleInterface,
842 sizeof(Params->Types.SingleInterface));
843
844 if (m_NumInterfaces > 1) {
846
849 "WDFUSBDEVICE %p cannot be auto configured for a single interface "
850 "since there are %d interfaces on the device, %!STATUS!",
852
853 return status;
854 }
855
856 RtlZeroMemory(&listEntry[0], sizeof(listEntry));
857
858 //
859 // Use AlternateSetting 0 by default
860 //
862
863 if (listEntry[0].InterfaceDescriptor == NULL) {
866 "WDFUSBDEVICE %p could not retrieve AlternateSetting 0 for "
867 "bInterfaceNumber %d", GetHandle(),
868 m_Interfaces[0]->m_InterfaceNumber);
869
871 }
872
875 &listEntry[0],
877
878 if (urb == NULL) {
880 }
881 else {
883
884 if (NT_SUCCESS(status)) {
885 Params->Types.SingleInterface.NumberConfiguredPipes =
887
888 Params->Types.SingleInterface.ConfiguredUsbInterface =
890 }
891
892 FxPoolFree(urb);
893 urb = NULL;
894 }
895
896 return status;
897}
898
904 )
905/*++
906
907Routine Description:
908 Selects the configuration as described by the parameter Params. If there is a
909 previous active configuration, the WDFUSBPIPEs for it are stopped and
910 destroyed before the new configuration is selected
911
912Arguments:
913 PipesAttributes - object attributes to apply to each created WDFUSBPIPE
914
915 Params -
916
917Return Value:
918 NTSTATUS
919
920 --*/
921{
923 PURB urb;
925 ULONG size;
926 UCHAR i;
928
930
931 Params->Types.MultiInterface.NumberOfConfiguredInterfaces = 0;
932
933 //
934 // The array needs an extra element which is zero'd out to mark the end
935 //
937 pList = (PUSBD_INTERFACE_LIST_ENTRY) FxPoolAllocate(
940 size
941 );
942
943 if (pList == NULL) {
945 }
946
948
950 for (i = 0; i < m_NumInterfaces; i++) {
951 pList[i].InterfaceDescriptor =
953
957 "WDFUSBDEVICE %p could not retrieve AlternateSetting 0 for "
958 "bInterfaceNumber %d", GetHandle(),
959 m_Interfaces[i]->m_InterfaceNumber);
960
962 goto Done;
963 }
964 }
965 }
966 else {
967 //
968 // Type is WdfUsbTargetDeviceSelectConfigTypeInterfacesPairs
969 //
970 UCHAR interfacePairsNum = 0;
971 UCHAR bitArray[UCHAR_MAX/sizeof(UCHAR)];
972
973 //
974 // initialize the bit array
975 //
976 RtlZeroMemory(bitArray, sizeof(bitArray));
977 //
978 // Build a list of descriptors from the Setting pairs
979 // passed in by the user. There could be interfaces not
980 // covered in the setting/interface pairs array passed.
981 // If that is the case return STATUS_INVALID_PARAMETER
982 //
983 for (i = 0; i < Params->Types.MultiInterface.NumberInterfaces ; i++) {
985 UCHAR interfaceNumber;
986 UCHAR altSettingIndex;
987
988 settingPair = &Params->Types.MultiInterface.Pairs[i];
989
991 settingPair->UsbInterface,
992 &interfaceNumber
993 );
994
995 //
996 //convert the interface handle to interface number
997 //
998 if (NT_SUCCESS(status)) {
999 altSettingIndex = settingPair->SettingIndex;
1000
1001 //
1002 // do the following only if the bit is not already set
1003 //
1004 if (FxBitArraySet(&bitArray[0], interfaceNumber) == FALSE) {
1005 pList[interfacePairsNum].InterfaceDescriptor =
1008 interfaceNumber,
1009 altSettingIndex
1010 );
1011
1012 if (pList[interfacePairsNum].InterfaceDescriptor == NULL) {
1017 "WDFUSBDEVICE %p could not retrieve "
1018 "AlternateSetting %d for "
1019 "bInterfaceNumber %d, returning %!STATUS!",
1020 GetHandle(),
1021 altSettingIndex, interfaceNumber, status);
1022 goto Done;
1023 }
1024
1025 interfacePairsNum++;
1026 }
1027 }
1028 else {
1029 goto Done;
1030 }
1031 }
1032
1033 //
1034 // Check if there are any interfaces not specified by the array. If
1035 // there are, then select setting 0 for them.
1036 //
1037 if (m_NumInterfaces > interfacePairsNum) {
1041 "WDFUSBDEVICE %p interface pairs set (%d) is not equal to actual "
1042 "# of interfaces (%d) reported by the device, %!STATUS!",
1043 GetObjectHandle(), interfacePairsNum, m_NumInterfaces, status);
1044 goto Done;
1045 }
1046 } //WdfUsbTargetDeviceSelectConfigTypeInterfacesPairs
1047
1051 pList,
1053 );
1054
1055 if (urb == NULL) {
1057 }
1058 else {
1061 urb,
1063 &Params->Types.MultiInterface.NumberOfConfiguredInterfaces);
1064
1065 FxPoolFree(urb);
1066 urb = NULL;
1067 }
1068
1069Done:
1071 pList = NULL;
1072
1073 return status;
1074}
1075
1079 VOID
1080 )
1081{
1083 FxSyncRequest request(GetDriverGlobals(), &context);
1084 FxRequestBuffer emptyBuffer;
1086
1087 //
1088 // FxSyncRequest always succeesds for KM.
1089 //
1090 status = request.Initialize();
1091 if (!NT_SUCCESS(status)) {
1093 "Failed to initialize FxSyncRequest");
1094 return status;
1095 }
1096
1097 status = FormatIoctlRequest(request.m_TrueRequest,
1099 TRUE,
1100 &emptyBuffer,
1101 &emptyBuffer);
1102 if (NT_SUCCESS(status)) {
1103 CancelSentIo();
1105 }
1106
1107 return status;
1108}
1109
1110
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
_Must_inspect_result_ NTSTATUS SubmitSync(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL, __out_opt PULONG Action=NULL)
_Must_inspect_result_ NTSTATUS SubmitSyncRequestIgnoreTargetState(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS RequestOptions)
MdDeviceObject m_TargetDevice
Definition: fxiotarget.hpp:910
MdDeviceObject m_InStackDevice
Definition: fxiotarget.hpp:905
_Must_inspect_result_ NTSTATUS FormatIoctlRequest(__in FxRequestBase *Request, __in ULONG Ioctl, __in BOOLEAN Internal, __in FxRequestBuffer *InputBuffer, __in FxRequestBuffer *OutputBuffer, __in_opt FxFileObject *FileObject=NULL)
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
_Must_inspect_result_ NTSTATUS Reset(VOID)
USBD_PIPE_HANDLE m_ControlPipe
_Must_inspect_result_ NTSTATUS SelectConfig(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb, __in FX_URB_TYPE FxUrbType, __out_opt PUCHAR NumConfiguredInterfaces)
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
_Must_inspect_result_ NTSTATUS FormatStringRequest(__in FxRequestBase *Request, __in FxRequestBuffer *RequestBuffer, __in UCHAR StringIndex, __in USHORT LangID)
_Must_inspect_result_ NTSTATUS QueryUsbCapability(__in CONST GUID *CapabilityType, __in ULONG CapabilityBufferLength, __drv_when(CapabilityBufferLength==0, __out_opt) __drv_when(CapabilityBufferLength !=0 &&ResultLength==NULL, __out_bcount(CapabilityBufferLength)) __drv_when(CapabilityBufferLength !=0 &&ResultLength !=NULL, __out_bcount_part_opt(CapabilityBufferLength, *ResultLength)) PVOID CapabilityBuffer, __out_opt __drv_when(ResultLength !=NULL, __deref_out_range(<=, CapabilityBufferLength)) PULONG ResultLength)
PINTERFACE_DEREFERENCE m_BusInterfaceDereference
PUSB_BUSIFFN_QUERY_BUS_TIME m_QueryBusTime
USBD_VERSION_INFORMATION m_UsbdVersionInformation
USBD_HANDLE m_USBDHandle
ULONG GetDefaultMaxTransferSize(VOID)
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
FX_URB_TYPE m_UrbType
UCHAR m_NumInterfaces
VOID CancelSentIo(VOID)
ULONG m_HcdPortCapabilities
_Must_inspect_result_ NTSTATUS FormatControlRequest(__in FxRequestBase *Request, __in PWDF_USB_CONTROL_SETUP_PACKET Packet, __in FxRequestBuffer *RequestBuffer)
_Must_inspect_result_ NTSTATUS GetString(__in_ecount(*NumCharacters) PUSHORT String, __in PUSHORT NumCharacters, __in UCHAR StringIndex, __in_opt USHORT LangID, __in_opt WDFREQUEST Request=NULL, __in_opt PWDF_REQUEST_SEND_OPTIONS Options=NULL)
PVOID m_BusInterfaceContext
_Must_inspect_result_ NTSTATUS GetInterfaceNumberFromInterface(__in WDFUSBINTERFACE UsbInterface, __out PUCHAR InterfaceNumber)
FX_URB_TYPE GetFxUrbTypeForRequest(__in FxRequestBase *Request)
_Must_inspect_result_ NTSTATUS InitDevice(__in ULONG USBDClientContractVersionForWdfClient)
_Must_inspect_result_ NTSTATUS SelectConfigSingle(__in PWDF_OBJECT_ATTRIBUTES PipeAttributes, __in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params)
FxUsbInterface ** m_Interfaces
_Must_inspect_result_ NTSTATUS SelectConfigMulti(__in PWDF_OBJECT_ATTRIBUTES PipeAttributes, __in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params)
USBD_HANDLE GetUSBDHandle(VOID)
BOOLEAN m_OnUSBD
PUSB_INTERFACE_DESCRIPTOR GetSettingDescriptor(__in UCHAR Setting)
WDFUSBINTERFACE GetHandle(VOID)
UCHAR GetNumConfiguredPipes(VOID)
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define __out_opt
Definition: dbghelp.h:65
#define __in_ecount(x)
Definition: dbghelp.h:47
#define __in
Definition: dbghelp.h:35
#define __out_bcount(x)
Definition: dbghelp.h:68
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
struct config_s config
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define __drv_when(cond, annotes)
Definition: driverspecs.h:335
#define NonPagedPool
Definition: env_spec_w32.h:307
FxChildList * pList
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PFX_DRIVER_GLOBALS pFxDriverGlobals
return pObject GetObjectHandle()
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
@ FX_RCT_USB_CONTROL_REQUEST
@ FX_RCT_USB_STRING_REQUEST
@ FxUrbTypeLegacy
Definition: fxusbdevice.hpp:27
@ FxUrbTypeUsbdAllocated
Definition: fxusbdevice.hpp:28
enum _FX_URB_TYPE FX_URB_TYPE
USHORT numChars
size_t bufferSize
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
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
#define UCHAR_MAX
Definition: limits.h:25
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define CONST
Definition: pedump.c:81
unsigned short USHORT
Definition: pedump.c:61
#define __deref_out_range(x, y)
Definition: sal_old.h:220
#define __out_bcount_part_opt(size, length)
Definition: sal_old.h:281
#define exit(n)
Definition: config.h:202
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
static VOID _FormatIrp(__in PIRP Irp, __in const GUID *InterfaceGuid, __out PINTERFACE Interface, __in USHORT InterfaceSize, __in USHORT InterfaceVersion, __in_opt PVOID InterfaceSpecificData=NULL)
virtual VOID StoreAndReferenceMemory(__in FxRequestBuffer *Buffer)
_URB_CONTROL_TRANSFER * m_Urb
Definition: fxusbdevice.hpp:86
_URB_CONTROL_TRANSFER m_UrbLegacy
Definition: fxusbdevice.hpp:81
__checkReturn NTSTATUS AllocateUrb(__in USBD_HANDLE USBDHandle)
Definition: fxusbdevice.cpp:70
VOID StoreAndReferenceMemory(__in FxUsbDevice *Device, __in FxRequestBuffer *Buffer, __in PWDF_USB_CONTROL_SETUP_PACKET SetupPacket)
VOID SetUrbInfo(__in UCHAR StringIndex, __in USHORT LangID)
_Must_inspect_result_ NTSTATUS AllocateDescriptor(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t BufferSize)
__checkReturn NTSTATUS AllocateUrb(__in USBD_HANDLE USBDHandle)
_URB_CONTROL_DESCRIPTOR_REQUEST m_UrbLegacy
_URB_CONTROL_DESCRIPTOR_REQUEST * m_Urb
VOID SetUsbType(__in WDF_USB_REQUEST_TYPE Type)
PMDL TransferBufferMDL
Definition: usb.h:472
USBD_PIPE_HANDLE PipeHandle
Definition: usb.h:468
ULONG TransferFlags
Definition: usb.h:469
ULONG TransferBufferLength
Definition: usb.h:470
PVOID TransferBuffer
Definition: usb.h:471
struct _URB_HEADER Hdr
Definition: usb.h:467
UCHAR SetupPacket[8]
Definition: usb.h:475
Definition: usb.h:529
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
Definition: usbdlib.h:7
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: usbdlib.h:8
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: usbbusif.h:98
PUSB_BUSIFFN_GETUSBDI_VERSION GetUSBDIVersion
Definition: usbbusif.h:99
PUSB_BUSIFFN_IS_DEVICE_HIGH_SPEED IsDeviceHighSpeed
Definition: usbbusif.h:103
PUSB_BUSIFFN_QUERY_BUS_TIME QueryBusTime
Definition: usbbusif.h:100
WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:522
Definition: http.c:7252
Definition: tftpd.h:86
Definition: ps.c:97
#define GetHandle(h)
Definition: treelist.c:116
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define USB_GETSTATUS_SELF_POWERED
Definition: usb100.h:45
struct _USB_CONFIGURATION_DESCRIPTOR * PUSB_CONFIGURATION_DESCRIPTOR
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
struct _USB_STRING_DESCRIPTOR * PUSB_STRING_DESCRIPTOR
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
#define USB_CONFIG_REMOTE_WAKEUP
Definition: usb100.h:71
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR
struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define URB_FUNCTION_CONTROL_TRANSFER
Definition: usb.h:94
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define USBD_DEFAULT_PIPE_TRANSFER
Definition: usb.h:156
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
#define USB_BUSIF_USBDI_VERSION_1
Definition: usbbusif.h:74
#define USB_BUSIF_USBDI_VERSION_0
Definition: usbbusif.h:73
NTSTATUS USBD_QueryUsbCapability(_In_ USBD_HANDLE USBDHandle, _In_ const GUID *CapabilityType, _In_ ULONG OutputBufferLength, _When_(OutputBufferLength==0, _Pre_null_) _When_(OutputBufferLength !=0 &&ResultLength==NULL, _Out_writes_bytes_(OutputBufferLength)) _When_(OutputBufferLength !=0 &&ResultLength !=NULL, _Out_writes_bytes_to_opt_(OutputBufferLength, *ResultLength)) PUCHAR OutputBuffer, _Out_opt_ _When_(ResultLength !=NULL, _Deref_out_range_(<=, OutputBufferLength)) PULONG ResultLength)
Definition: usbdex.c:10
NTSTATUS USBD_CreateHandle(_In_ PDEVICE_OBJECT DeviceObject, _In_ PDEVICE_OBJECT TargetDeviceObject, _In_ ULONG USBDClientContractVersion, _In_ ULONG PoolTag, _Out_ USBD_HANDLE *USBDHandle)
Definition: usbdex.c:38
#define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link)
Definition: usbdlib.h:23
#define UsbBuildGetStatusRequest(urb, op, index, transferBuffer, transferBufferMDL, link)
Definition: usbdlib.h:35
struct _USBD_INTERFACE_LIST_ENTRY * PUSBD_INTERFACE_LIST_ENTRY
struct _USBD_INTERFACE_LIST_ENTRY USBD_INTERFACE_LIST_ENTRY
#define USBD_CLIENT_CONTRACT_VERSION_INVALID
Definition: usbdlib.h:99
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35
PUSB_INTERFACE_DESCRIPTOR FxUsbParseConfigurationDescriptor(__in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in UCHAR InterfaceNumber, __in UCHAR AlternateSetting)
Definition: usbutil.cpp:309
PURB FxUsbCreateConfigRequest(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, __in PUSBD_INTERFACE_LIST_ENTRY InterfaceList, __in ULONG DefaultMaxPacketSize)
Definition: usbutil.cpp:366
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
BOOLEAN __inline FxBitArraySet(__inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR BitArray, __in UCHAR BitNumber)
Definition: usbutil.hpp:9
#define WDFCASSERT(c)
Definition: wdfassert.h:93
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4071
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(_Inout_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ LONGLONG Timeout)
Definition: wdfrequest.h:421
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipeAttributes
Definition: wdfusb.h:1242
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2334
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ CONST GUID _In_ ULONG CapabilityBufferLength
Definition: wdfusb.h:1615
@ WDF_USB_DEVICE_TRAIT_SELF_POWERED
Definition: wdfusb.h:142
@ WDF_USB_DEVICE_TRAIT_AT_HIGH_SPEED
Definition: wdfusb.h:144
@ WDF_USB_DEVICE_TRAIT_REMOTE_WAKE_CAPABLE
Definition: wdfusb.h:143
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT NumCharacters
Definition: wdfusb.h:1078
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ CONST GUID * CapabilityType
Definition: wdfusb.h:1613
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR StringIndex
Definition: wdfusb.h:1080
@ WdfUsbRequestTypeDeviceControlTransfer
Definition: wdfusb.h:90
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1083
@ WdfUsbTargetDeviceSelectConfigTypeMultiInterface
Definition: wdfusb.h:129
union _WDF_USB_CONTROL_SETUP_PACKET * PWDF_USB_CONTROL_SETUP_PACKET
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET SetupPacket
Definition: wdfusb.h:1337
_Must_inspect_result_ _In_ WDFUSBINTERFACE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipesAttributes
Definition: wdfusb.h:2390
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
@ IoModifyAccess
Definition: ketypes.h:917
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180