ReactOS 0.4.16-dev-1946-g52006dd
fxusbdevice.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxUsbDevice.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 "FxUsbDevice.tmh"
31#endif
32
33#define RtlSizeTToULong RtlULongPtrToULong
34}
35
36#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
37#define UCHAR_MAX (0xff)
38#endif
39
41 __in FX_URB_TYPE FxUrbType
42 ) :
44{
48
49 if (FxUrbType == FxUrbTypeLegacy) {
51 }
52 else {
53 m_Urb = NULL;
54 }
55}
56
58 VOID
59 )
60{
61 if (m_Urb && (m_Urb != &m_UrbLegacy)) {
63 }
64 m_Urb = NULL;
66}
67
71 __in USBD_HANDLE USBDHandle
72 )
73{
75
77 ASSERT(m_Urb == NULL);
78
80
81 if (!NT_SUCCESS(status)) {
82 goto Done;
83 }
84
86
87Done:
88 return status;
89}
90
91VOID
93 VOID
94 )
95{
96 if (m_Urb && (m_Urb != &m_UrbLegacy)){
98 m_Urb = NULL;
100 }
101}
102
103VOID
106 )
107{
108#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
111#elif (FX_CORE_MODE == FX_CORE_USER_MODE)
114#endif
116}
117
118VOID
121 )
122{
123 //
124 // Check now because Init will NULL out the field
125 //
126 if (m_PartialMdl != NULL) {
127 if (m_UnlockPages) {
130 }
131
132#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
133 FxMdlFree(Request->GetDriverGlobals(), m_PartialMdl);
134#endif
136 }
137
139}
140
143 VOID
144 )
145{
146 return m_Urb->Hdr.Status;
147}
148
150 __in FX_URB_TYPE FxUrbType
151 ) :
153{
158
159 if (FxUrbType == FxUrbTypeLegacy) {
162 m_Urb->Hdr.Length = sizeof(*m_Urb);
164 }
165 else {
166 m_Urb = NULL;
167 }
168}
169
171 VOID
172 )
173{
174 if (m_StringDescriptor != NULL) {
177 }
178
179 if (m_Urb && (m_Urb != &m_UrbLegacy)){
181 }
182 m_Urb = NULL;
184}
185
189 __in USBD_HANDLE USBDHandle
190 )
191{
193
195 ASSERT(m_Urb == NULL);
196
198
199 if (!NT_SUCCESS(status)) {
200 goto Done;
201 }
202
204
206 m_Urb->Hdr.Length = sizeof(*m_Urb);
208
209Done:
210 return status;
211}
212
213VOID
215 VOID
216 )
217{
218 if (m_Urb && (m_Urb != &m_UrbLegacy)){
220 m_Urb = NULL;
222 }
223
224}
225
226VOID
229 )
230{
231 //
232 // Make sure we got an even number of bytes and that we got a header
233 //
234 if ((m_StringDescriptor->bLength & 0x1) ||
237 }
238 else if (NT_SUCCESS(Request->GetSubmitFxIrp()->GetStatus())) {
239 //
240 // No matter what, indicate the required size to the caller
241 //
244
245 if (m_UsbParameters.Parameters.DeviceString.RequiredSize >
247 //
248 // Too much string to fit into the buffer supplied by the client.
249 // Morph the status into a warning. Copy as much as we can.
250 //
255 }
256 else {
257 //
258 // Everything fits, copy it over
259 //
262
266 }
267 }
268
270}
271
272VOID
276 )
277{
279
281
282#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
285
288#elif (FX_CORE_MODE == FX_CORE_USER_MODE)
291
294#endif
295}
296
299 VOID
300 )
301{
302 return m_Urb->Hdr.Status;
303}
304
308 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
309 __in size_t BufferSize
310 )
311{
312 PUSB_STRING_DESCRIPTOR pDescriptor;
313 size_t length;
315
317 return STATUS_SUCCESS;
318 }
319
320 length = sizeof(USB_STRING_DESCRIPTOR) - sizeof(pDescriptor->bString[0]) +
322
323 pDescriptor = (PUSB_STRING_DESCRIPTOR) FxPoolAllocate(
324 FxDriverGlobals,
326 length);
327
328 if (pDescriptor == NULL) {
330 }
331
332 if (m_StringDescriptor != NULL) {
334 }
335
336 RtlZeroMemory(pDescriptor, length);
337
338 m_StringDescriptor = pDescriptor;
339
341
342 return status;
343}
344
346 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
347 __in USBD_HANDLE USBDHandle,
349 __in size_t BufferSize
350 ) :
351 FxMemoryBufferPreallocated(FxDriverGlobals, sizeof(*this), Buffer, BufferSize),
352 m_USBDHandle(USBDHandle)
353{
355}
356
358{
359}
360
363 VOID
364 )
365{
369 m_pBuffer = NULL;
371
372 return FxMemoryBufferPreallocated::Dispose(); // __super call
373}
374
376 __in PFX_DRIVER_GLOBALS FxDriverGlobals
377 ) :
379{
382
383 m_OnUSBD = FALSE;
385 m_NumInterfaces = 0;
386
387 m_Traits = 0;
395
397
400
401#if (FX_CORE_MODE == FX_CORE_USER_MODE)
404#endif
405
407}
408
411 VOID
412 )
413{
414#if ((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE))
415 KeFlushQueuedDpcs();
416#endif
417
418 if (m_USBDHandle) {
421 }
422
423#if (FX_CORE_MODE == FX_CORE_USER_MODE)
424 IWudfDevice* device = NULL;
425 IWudfDeviceStack* devstack = NULL;
426
428 devstack = device->GetDeviceStackInterface();
429
430 if (m_pHostTargetFile) {
431 devstack->CloseFile(m_pHostTargetFile);
433 }
434#endif
435
436 return FxIoTarget::Dispose(); // __super call
437}
438
440{
441 UCHAR i;
442
446 }
447
448 if (m_ConfigDescriptor != NULL) {
451 }
452
453 for (i = 0; i < m_NumInterfaces; i++) {
455 }
456
457 if (m_Interfaces != NULL){
460 }
461
462 m_NumInterfaces = 0;
463}
464
465VOID
468 )
469{
470 UCHAR i;
471
472 if (m_Interfaces == NULL) {
473 return;
474 }
475
476 for (i = 0; i < m_NumInterfaces; i++) {
477 if (m_Interfaces[i] == Interface) {
479 return;
480 }
481 }
482}
483
484VOID
487 )
488{
489 Information->Traits = m_Traits;
490 Information->HcdPortCapabilities = m_HcdPortCapabilities;
491
492 RtlCopyMemory(&Information->UsbdVersionInformation,
495}
496
497ULONG
499 VOID
500 )
501/*++
502
503Routine Description:
504 Determines the default max transfer size based on the usb host controller
505 and OS we are running on. What it boils down to is that on XP and later
506 the usb core ignores the default max transfer size, but it does use the
507 value on Windows 2000. To make life fun, there is only one definition of
508 USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE whose value changes depending on header
509 versioning. Since we are versioned for the latest OS, we do not pick up the
510 Win2k value by using the #define, rather we have to use the value that we
511 *would* have picked up if we were header versioned for Win2k.
512
513 NOTE: we could be on win2k with a usbport serviced stack. in this case,
514 usbport doesn't care about max transfer sizes
515
516Arguments:
517 None
518
519Return Value:
520 usb core and OS appropriate default max transfer size.
521
522 --*/
523{
524 //
525 // On a usbport serviced stack (which can be running on Win2k) or on a
526 // usbd stack on XP and later. In any case, always use the current max
527 // transfer size definition.
528 //
530}
531
535 VOID
536 )
537{
539
541
542 if (NT_SUCCESS(status)) {
545 ULONG i, iInterface;
547 KIRQL irql;
548
550
551 Lock(&irql);
552
553 //
554 // Iterate over all of the interfaces. For each pipe on each interface,
555 // grab all pended i/o for later submission.
556 //
557 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++){
558
559 pUsbInterface = m_Interfaces[iInterface];
560
561 for (i = 0; i < pUsbInterface->m_NumberOfConfiguredPipes; i++) {
563 }
564 }
565 Unlock(irql);
566
567 //
568 // Since we are going to reference the FxUsbPipe's outside of the
569 // lock and the interface can go away in the meantime, add a reference
570 // (multiple times perhaps) to each FxUsbPipe to make sure it sticks
571 // around.
572 //
573 for (ple = head.Flink; ple != &head; ple = ple->Flink) {
575 pRequest->GetTarget()->ADDREF(this);
576 }
577
578 //
579 // Drain the list of pended requests.
580 //
581 while (!IsListEmpty(&head)) {
583
585
587
589
591
592 //
593 // Release the reference taken above when accumulating pended i/o.
594 //
595 pTarget->RELEASE(this);
596 }
597 }
598
599 return status;
600}
601
602#define STOP_TAG (PVOID) 'pots'
603
604VOID
607 )
608{
611 ULONG iPipe, iInterface;
612 KIRQL irql;
613
614 head.Next = NULL;
615
616 //
617 // Stop all of our own I/O first
618 //
620
621 //
622 // if we are just canceling i/o, then we just acquire the spin lock b/c
623 // we can be called at dispatch level for this action code.
624 //
627
628 AcquireInterfaceIterationLock();
629 }
630
631 //
632 // Since we don't have to synchronize on the I/O already sent, just set
633 // each pipe's state to stop.
634 //
635 Lock(&irql);
636
637 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
638 pUsbInterface = m_Interfaces[iInterface];
639
641 for (iPipe = 0;
643 iPipe++) {
644
645 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
646 BOOLEAN wait;
647
648 wait = FALSE;
649
651 Action,
652 &head,
653 &wait,
654 TRUE
655 );
656 }
657 }
658 }
659 }
660 Unlock(irql);
661
662 //
663 // If we are leaving sent IO pending, the io target will set the IO
664 // completion event during stop even if there is still outstanding IO.
665 //
666
667 if (head.Next != NULL) {
669 }
670
671 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
672 pUsbInterface = m_Interfaces[iInterface];
673
675 //
676 // Iterate over the pipes and clean each one up
677 //
678 for (iPipe = 0;
680 iPipe++) {
681 //
682 // Same reason as above
683 //
684 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
687 }
688 }
689 }
690 }
691
693 ReleaseInterfaceIterationLock();
694 }
695}
696
697VOID
700 )
701{
703 SINGLE_LIST_ENTRY sentHead;
704 ULONG iPipe, iInterface;
705 KIRQL irql;
706
707 sentHead.Next = NULL;
708
709 //
710 // Purge all of our own I/O first
711 //
713
714 //
715 // if we are just canceling i/o, then we just acquire the spin lock b/c
716 // we can be called at dispatch level for this action code.
717 //
718 if (Action != WdfIoTargetPurgeIo) {
720
721 AcquireInterfaceIterationLock();
722 }
723
724 //
725 // Since we don't have to synchronize on the I/O already sent, just set
726 // each pipe's state to purged.
727 //
728 Lock(&irql);
729
730 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
731 pUsbInterface = m_Interfaces[iInterface];
732
734 for (iPipe = 0;
736 iPipe++) {
737
738 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
739 BOOLEAN wait;
740 LIST_ENTRY pendedHead;
741
742 wait = FALSE;
743 InitializeListHead(&pendedHead);
744
746 Action,
747 &pendedHead,
748 &sentHead,
749 &wait,
750 TRUE
751 );
752
753 //
754 // Complete any requests pulled off from this pipe.
755 //
757 CompletePendedRequestList(&pendedHead);
758 }
759 }
760 }
761 }
762 Unlock(irql);
763
764 //
765 // Cancel all sent requests.
766 //
767 _CancelSentRequests(&sentHead);
768
769 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
770 pUsbInterface = m_Interfaces[iInterface];
771
773 //
774 // Iterate over the pipes and clean each one up
775 //
776 for (iPipe = 0;
778 iPipe++) {
779 //
780 // Same reason as above
781 //
782 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
785 }
786 }
787 }
788 }
789
790 if (Action != WdfIoTargetPurgeIo) {
791 ReleaseInterfaceIterationLock();
792 }
793}
794
795VOID
797 __in PLIST_ENTRY PendHead,
798 __in PSINGLE_LIST_ENTRY SentHead
799 )
800{
801 while (!IsListEmpty(PendHead)) {
804
805 ple = RemoveHeadList(PendHead);
806
808
811 }
812
813 _CancelSentRequests(SentHead);
814}
815
816VOID
818 __in BOOLEAN ForceRemovePipes
819 )
820{
821 SINGLE_LIST_ENTRY sentHead;
822 LIST_ENTRY pendHead, interfaceHead;
824 ULONG iPipe, intfIndex;
825 KIRQL irql;
826
827 sentHead.Next = NULL;
828 InitializeListHead(&pendHead);
829 InitializeListHead(&interfaceHead);
830
831 AcquireInterfaceIterationLock();
832
833 Lock(&irql);
834 for (intfIndex = 0; intfIndex < m_NumInterfaces; intfIndex++ ) {
835 pUsbInterface = m_Interfaces[intfIndex];
836
838 for (iPipe = 0;
840 iPipe++) {
841 BOOLEAN wait;
842
843 wait = FALSE;
844
845 //
846 // Pipe can be NULL if the interface is half initialized
847 //
848 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
851 &pendHead,
852 &sentHead,
853 TRUE,
854 &wait);
855
856 }
857 }
858 }
859 }
860 Unlock(irql);
861
862 //
863 // We cleanup requests no matter what the new state is because we complete all
864 // pended requests in the surprise removed case.
865 //
866 _CleanupPipesRequests(&pendHead, &sentHead);
867
868 //
869 // Only destroy child pipe objects when the parent is going away or the
870 // caller indicates that this is the desired action.
871 //
872 if (m_State == WdfIoTargetDeleted || ForceRemovePipes) {
873 for (intfIndex = 0; intfIndex < m_NumInterfaces; intfIndex++) {
874 pUsbInterface = m_Interfaces[intfIndex];
875
877 //
878 // Iterate over the pipes and clean each one up
879 //
880 for (iPipe = 0;
882 iPipe++) {
883 //
884 // Same reason as above
885 //
886 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
889 }
890 }
891 }
892
894 }
895 }
896
897 ReleaseInterfaceIterationLock();
898}
899
903 VOID
904 )
905{
907 UCHAR descCountBitMap[UCHAR_MAX / sizeof(UCHAR)];
908 PUSB_INTERFACE_DESCRIPTOR pInterfaceDescriptor;
909 UCHAR iInterface, numFound;
911 ULONG size;
912 ULONG totalLength;
913
916 totalLength = m_ConfigDescriptor->wTotalLength;
917
918 //
919 // Make sure each PCOMMON_DESCRIPTOR_HEADER within the entire config descriptor is well formed.
920 // If successful, we can walk the config descriptor using common headers without any more top
921 // level error checking. Task specific checking of the specialized header types must still occur.
922 //
927 );
928
929 if (!NT_SUCCESS(status)) {
932 "Validation of the config descriptor failed due to a bad common descriptor header, %!STATUS!",
933 status);
934 return status;
935 }
936
937 //
938 // Validate all interface descriptors in config descriptor are at least
939 // sizeof(USB_INTERFACE_DESCRIPTOR).
940 //
941
942
943
944
945
954 0
955 );
956
957 if (!NT_SUCCESS(status)) {
960 "Validation of interface descriptors in config descriptor failed, %!STATUS!",
961 status);
962
963 return status;
964 }
965
967 //
968 // Use an array of one in the zero case
969 //
970 size = sizeof(FxUsbInterface*);
971 }
972 else {
974 }
975
976 //
977 // Allocate an array large enough to hold pointers to interfaces
978 //
980 FxPoolAllocate(pFxDriverGlobals, NonPagedPool, size);
981
982 if (m_Interfaces == NULL) {
984
987 "Could not allocate memory for %d interfaces, %!STATUS!",
989
990 goto Done;
991 }
992
995
996 //
997 // Iterate over the desciptors again, this time allocating an FxUsbInterface
998 // for each one and capturing the interface information.
999 //
1000 RtlZeroMemory(descCountBitMap, sizeof(descCountBitMap));
1001 iInterface = 0;
1002 numFound = 0;
1003 UNREFERENCED_PARAMETER(numFound);
1004
1005 pInterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR) FxUsbFindDescriptorType(
1010 );
1011
1012 while (pInterfaceDescriptor != NULL &&
1013 iInterface < m_ConfigDescriptor->bNumInterfaces) {
1014
1015 //
1016 // This function will retun false if the bit wasn't already set
1017 //
1018 if (FxBitArraySet(descCountBitMap,
1019 pInterfaceDescriptor->bInterfaceNumber) == FALSE) {
1021
1024 this,
1025 pInterfaceDescriptor);
1026
1027 if (pInterface == NULL) {
1031 "Could not allocate memory for interface object #%d, %!STATUS!",
1032 iInterface, status);
1033 goto Done;
1034 }
1035
1037
1038 //
1039 // This should never fail
1040 //
1042
1043 if (!NT_SUCCESS(status)) {
1044 goto Done;
1045 }
1046
1047 status = pInterface->CreateSettings();
1048 if (!NT_SUCCESS(status)) {
1049 goto Done;
1050 }
1051
1052#if (FX_CORE_MODE == FX_CORE_USER_MODE)
1053 status = pInterface->SetWinUsbHandle(iInterface);
1054 if (!NT_SUCCESS(status)) {
1055 goto Done;
1056 }
1057
1058 status = pInterface->MakeAndConfigurePipes(WDF_NO_OBJECT_ATTRIBUTES,
1059 pInterfaceDescriptor->bNumEndpoints);
1060 if (!NT_SUCCESS(status)) {
1061 goto Done;
1062 }
1063#endif
1064
1065 m_Interfaces[iInterface] = pInterface;
1066
1067 iInterface++;
1068 }
1069
1070 pInterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR) FxUsbFindDescriptorType(
1072 totalLength,
1073 WDF_PTR_ADD_OFFSET(pInterfaceDescriptor,
1074 pInterfaceDescriptor->bLength),
1076 );
1077 }
1078
1079 //
1080 // We cannot check for the error case of
1081 //
1082 // pInterfaceDescriptor != NULL &&
1083 // iInterface == m_ConfigDescriptor->bNumInterfaces
1084 //
1085 // Because if there are multiple alternative settings for the last interface
1086 // in the config descriptor, we will have hit the limit of interfaces
1087 // (correctly), but have found another pInterfaceDescriptor (the next alt
1088 // setting).
1089 //
1090
1091 //
1092 // We already logged and found the case where iInterface >= m_NumInterfaces.
1093 // Check for the case where we found too few interfaces and when we found
1094 // no interfaces even though the config descriptor says otherwise.
1095 //
1096 //
1097 if (iInterface == 0 && m_NumInterfaces > 0) {
1099
1102 "Config descriptor indicated there were %d interfaces, but did not "
1103 "find any interface descriptors in config descriptor %p, %!STATUS!",
1105 }
1106 else if (pInterfaceDescriptor != NULL && m_NumInterfaces == 0) {
1109 "Config descriptor indicated there were 0 interfaces, but an interface "
1110 "descriptor was found");
1111
1113 }
1114 else if (iInterface < m_NumInterfaces) {
1117 "Config descriptor indicated there were %d interfaces, only found "
1118 "%d interfaces", m_NumInterfaces, iInterface);
1119
1120 //
1121 // Instead of considering this an error, just use the number found.
1122 // This will not have an adverse affect elsewhere and since the framework
1123 // is probably more strict then previous USB code, this would have not
1124 // been found earlier by a WDM driver.
1125 //
1126 m_NumInterfaces = iInterface;
1127 }
1128
1129Done:
1130 return status;
1131}
1132
1133
1138 )
1139{
1141
1144 FxSyncRequest syncRequest(GetDriverGlobals(), &context);
1145
1146 //
1147 // FxSyncRequest always succeesds for KM.
1148 //
1149 status = syncRequest.Initialize();
1150 if (!NT_SUCCESS(status)) {
1152 "Failed to initialize FxSyncRequest");
1153 return status;
1154 }
1155
1156 *PortStatus = 0;
1157 args[0].SetBuffer(PortStatus, 0);
1158 args[1].SetBuffer(NULL, 0);
1159 args[2].SetBuffer(NULL, 0);
1160
1161 status = FormatInternalIoctlOthersRequest(syncRequest.m_TrueRequest,
1163 args);
1164
1165 if (NT_SUCCESS(status)) {
1167
1170
1171 status = SubmitSync(syncRequest.m_TrueRequest, &options);
1172 }
1173
1174 return status;
1175}
1176
1177
1178
1179BOOLEAN
1181 VOID
1182 )
1183{
1185 ULONG portStatus;
1187
1188 enabled = TRUE;
1189 status = GetPortStatus(&portStatus);
1190
1191 //
1192 // Inability to get STATUS_SUCCESS from GetPortStatus is more likely a resource
1193 // issue rather than a device issue so return FALSE from this function only if
1194 // we were able to read the PortStatus and the port was disabled.
1195 // What you don't want is to continuosly reset the device (by returning FALSE)
1196 // instead of resetting pipe (by returning TRUE) under low memory conditions.
1197 //
1198 if (NT_SUCCESS(status) && (portStatus & USBD_PORT_ENABLED) == 0) {
1199 enabled = FALSE;
1200 }
1201
1202 return enabled;
1203}
1204
1208 VOID
1209 )
1210{
1211#if (FX_CORE_MODE == FX_CORE_USER_MODE)
1212
1213
1214
1215
1216 return STATUS_UNSUCCESSFUL;
1217#elif (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
1219 ULONG portStatus;
1220
1221 status = GetPortStatus(&portStatus);
1222 if (NT_SUCCESS(status) && (portStatus & USBD_PORT_CONNECTED) == 0) {
1224 }
1225
1226 return status;
1227#endif
1228}
1229
1233 VOID
1234 )
1235{
1237 FxSyncRequest request(GetDriverGlobals(), &context);
1239
1240 //
1241 // FxSyncRequest always succeesds for KM.
1242 //
1243 status = request.Initialize();
1244 if (!NT_SUCCESS(status)) {
1246 "Failed to initialize FxSyncRequest");
1247 return status;
1248 }
1249
1250 status = FormatCycleRequest(request.m_TrueRequest);
1251
1252 if (NT_SUCCESS(status)) {
1253 CancelSentIo();
1255 //
1256 // NOTE: CyclePort causes the device to be removed and re-enumerated so
1257 // don't do anymore operations after this point.
1258 //
1259 }
1260
1261 return status;
1262}
1263
1268 )
1269{
1270 FxRequestBuffer emptyBuffer;
1271
1274 TRUE,
1275 &emptyBuffer,
1276 &emptyBuffer);
1277}
1278
1284 )
1285{
1287 USHORT copyLength;
1288
1289 if (ConfigDescriptor == NULL) {
1290 //
1291 // Caller wants length to allocate
1292 //
1295 }
1296
1297 if (*ConfigDescriptorLength < m_ConfigDescriptor->wTotalLength) {
1298 //
1299 // Valid ConfigDescriptor passed in, but its too small. Copy as many
1300 // bytes as we can.
1301 //
1302 copyLength = *ConfigDescriptorLength;
1304 }
1305 else {
1306 copyLength = m_ConfigDescriptor->wTotalLength;
1308 }
1309
1310 //
1311 // Always indicate to the caller the number of required bytes or the
1312 // number of bytes we copied.
1313 //
1316
1317 return status;
1318}
1319
1325 )
1326{
1327 PUSBD_INTERFACE_LIST_ENTRY pInterfaces;
1328 PURB urb;
1330 ULONG i, size;
1331 PUSB_CONFIGURATION_DESCRIPTOR configurationDescriptor;
1332 PUSB_INTERFACE_DESCRIPTOR* interfaceDescriptors;
1333 ULONG numInterfaces;
1335
1337
1338 configurationDescriptor = Params->Types.Descriptor.ConfigurationDescriptor;
1339 interfaceDescriptors = Params->Types.Descriptor.InterfaceDescriptors;
1340 numInterfaces = Params->Types.Descriptor.NumInterfaceDescriptors;
1341
1342 for (i = 0; i < numInterfaces; i++) {
1343 if (interfaceDescriptors[i] == NULL) {
1345 }
1346 }
1347
1348 //
1349 // eventually size = sizeof(USBD_INTERFACE_LIST_ENTRY) * (numInterfaces + 1)
1350 //
1351 status = RtlULongAdd(numInterfaces, 1, &size);
1352 if (!NT_SUCCESS(status)) {
1353 return status;
1354 }
1355
1356 status = RtlULongMult(size, sizeof(USBD_INTERFACE_LIST_ENTRY), &size);
1357 if (!NT_SUCCESS(status)) {
1358 return status;
1359 }
1360
1361 pInterfaces = (PUSBD_INTERFACE_LIST_ENTRY) FxPoolAllocate(
1363
1364 if (pInterfaces == NULL) {
1366
1369 "Could not allocate array of USBD_INTERFACE_LIST_ENTRY, %!STATUS!",
1370 status);
1371
1372 return status;
1373 }
1374
1375 RtlZeroMemory(pInterfaces, size);
1376
1377 for (i = 0; i < numInterfaces; i++) {
1378 pInterfaces[i].InterfaceDescriptor = interfaceDescriptors[i];
1379 }
1380
1381 if (configurationDescriptor == NULL) {
1382 configurationDescriptor = m_ConfigDescriptor;
1383 }
1384
1385 //
1386 // NOTE:
1387 //
1388 // Creating a config request using the caller's config descriptor does not
1389 // currently work if the provided config descriptor is not the same as the
1390 // descriptor reported by the device. It does not work because we try to
1391 // validate the interface number in the URB against an existing
1392 // FxUsbInterface (which is based on the config descriptor described by the
1393 // device, not the provided one), and if that validation fails, we return
1394 // !NT_SUCCESS from SelectConfig().
1395 //
1397 configurationDescriptor,
1398 pInterfaces,
1400 if (urb == NULL) {
1402 }
1403 else {
1405 FxPoolFree(urb);
1406 urb = NULL;
1407 }
1408
1409 FxPoolFree(pInterfaces);
1410 pInterfaces = NULL;
1411
1412 return status;
1413}
1414
1416 //
1417 // Array of pipes
1418 //
1420
1421 //
1422 // Number of entries in Pipes
1423 //
1425};
1426
1431 __in PURB Urb,
1432 __in FX_URB_TYPE FxUrbType,
1433 __out_opt PUCHAR NumConfiguredInterfaces
1434 )
1435/*++
1436
1437Routine Description:
1438 Selects the configuration as described by the parameter Urb. If there is a
1439 previous active configuration, the WDFUSBPIPEs for it are stopped and
1440 destroyed before the new configuration is selected
1441
1442Arguments:
1443 PipesAttributes - object attributes to apply to each created WDFUSBPIPE
1444
1445 Urb - the URB describing the configuration to select
1446
1447Return Value:
1448 NTSTATUS
1449
1450 --*/
1451{
1453 PUCHAR pCur, pEnd;
1455 FxUsbPipe* pPipe;
1456 PURB pSelectUrb;
1458 ULONG iPipe;
1459 USHORT maxNumPipes, size;
1460 UCHAR numPipes;
1461 FxInterfacePipeInformation* pPipeInfo;
1464 UCHAR intfIndex;
1465 FxIrp* irp;
1466
1468 FxSyncRequest request(GetDriverGlobals(), NULL);
1469
1470 pIface = NULL;
1471 maxNumPipes = 0;
1472 size = 0;
1473 pPipeInfo = NULL;
1474 pSelectUrb = NULL;
1475
1476 //
1477 // Callers to this function have guaranteed that there are interfaces
1478 // reported on this device.
1479 //
1480 ASSERT(m_NumInterfaces != 0);
1481
1482 if (NumConfiguredInterfaces != NULL) {
1483 *NumConfiguredInterfaces = 0;
1484 }
1485
1486 //
1487 // FxSyncRequest always succeesds for KM but can fail for UM.
1488 //
1489 status = request.Initialize();
1490 if (!NT_SUCCESS(status)) {
1492 "Failed to initialize FxSyncRequest");
1493 goto Done;
1494 }
1495
1496 //
1497 // Allocate a PIRP for the select config and possible select interface(s)
1498 //
1499 status = request.m_TrueRequest->ValidateTarget(this);
1500 if (!NT_SUCCESS(status)) {
1501 goto Done;
1502 }
1503
1504 //
1505 // Allocate a pool for storing the FxUsbPipe ** before we
1506 // assign them to the Interfaces just in case all doesn't go well.
1507 //
1508 if (m_NumInterfaces == 0) {
1509 //
1510 // Use one in the zero case to make the logic simpler
1511 //
1513 }
1514 else {
1516 }
1517
1518 pPipeInfo = (FxInterfacePipeInformation*) FxPoolAllocate(
1520 );
1521
1522 if (pPipeInfo == NULL) {
1526 "Could not internal allocate tracking info for selecting a config on "
1527 "WDFUSBDEVICE 0x%p, %!STATUS!", GetHandle(), status);
1528 goto Done;
1529 }
1530
1531 RtlZeroMemory(pPipeInfo, size);
1532
1533 //
1534 // The following code and the one in select setting have a lot in common
1535 // but can't leverage on that as that sends the select interface URB down
1536 // Our goal is allocate the resources -- the pipes and the select setting URB
1537 // before sending down the select config URB so that the tear down is simpler.
1538 //
1539
1540 //
1541 // Each FxUsbInterface will need a FxUsbPipe* for each pipe contained in
1542 // the interface.
1543 //
1544 pCur = (PUCHAR) &Urb->UrbSelectConfiguration.Interface;
1545 pEnd = ((PUCHAR) Urb) + Urb->UrbSelectConfiguration.Hdr.Length;
1546 intfIndex = 0;
1547
1548 for ( ; pCur < pEnd; pCur += pIface->Length, intfIndex++) {
1549 FxUsbPipe** ppPipes;
1550
1552 if (pIface->NumberOfPipes > UCHAR_MAX) {
1556 "WDFUSBDEVICE supports a maximum of %d pipes per interface, "
1557 "USBD_INTERFACE_INFORMATION %p specified %d, %!STATUS!",
1558 UCHAR_MAX, pIface, pIface->NumberOfPipes, status);
1559 goto Done;
1560 }
1561
1563 if (pUsbInterface == NULL) {
1567 "Could not find an instance of an interface descriptor with "
1568 "InterfaceNumber %d, %!STATUS!",
1569 pIface->InterfaceNumber, status);
1570 goto Done;
1571 }
1572
1573 numPipes = (UCHAR) pIface->NumberOfPipes;
1574
1575 //
1576 // Track the maximum number of pipes we have seen in an interface in
1577 // case we need to allocate a select interface URB.
1578 //
1579 if (numPipes > maxNumPipes) {
1580 maxNumPipes = (USHORT) numPipes;
1581 }
1582
1583 if (numPipes > 0) {
1584 size = numPipes * sizeof(FxUsbPipe *);
1585 }
1586 else {
1587 //
1588 // It is valid to have an interface with zero pipes in it. In that
1589 // case, we just allocate one entry so that we have a valid array
1590 // and keep the remaining code simple.
1591 //
1592 size = sizeof(FxUsbPipe*);
1593 }
1594
1595 ppPipes = (FxUsbPipe**) FxPoolAllocate(
1598 size
1599 );
1600
1601 if (ppPipes == NULL) {
1605 "Could not allocate memory for Pipes "
1606 "InterfaceNumber %d, %!STATUS!",
1607 pIface->InterfaceNumber, status);
1608 goto Done;
1609 }
1610
1611 RtlZeroMemory(ppPipes, size);
1612
1613 //
1614 // We store the pointer to the newly allocated arary in a temporary b/c
1615 // we can still fail and we don't want a half baked interface.
1616 //
1617
1618 pPipeInfo[intfIndex].Pipes = ppPipes;
1619 pPipeInfo[intfIndex].NumPipes = numPipes;
1620
1621 for (iPipe = 0; iPipe < numPipes; iPipe++) {
1622 ppPipes[iPipe] = new (GetDriverGlobals(), PipesAttributes)
1624
1625 if (ppPipes[iPipe] == NULL) {
1629 "Could not allocate a pipe object, %!STATUS!", status);
1630 goto Done;
1631 }
1632
1633 pPipe = ppPipes[iPipe];
1634 status = pPipe->Init(m_Device);
1635 if (!NT_SUCCESS(status)) {
1638 "Could not Init the pipe object, %!STATUS!", status);
1639 goto Done;
1640 }
1641
1643 if (!NT_SUCCESS(status)) {
1646 "Could not commit the pipe object, %!STATUS!", status);
1647 goto Done;
1648 }
1649 }
1650
1651
1652
1653
1654
1655
1656
1657
1658
1661 }
1662 }
1663
1664 //
1665 // If we are selecting more then one interface and at least one of them
1666 // has pipes in them, allocate a select interface URB that will be used
1667 // after the select config to select each interface. The select interface
1668 // URB will be big enough to select the largest interface in the group.
1669 //
1670 // The select interface URB is allocated before the select config so that
1671 // we know once the select config has completed successfully, we can be
1672 // guaranteed that we can select the interfaces we want and not have to
1673 // handle undoing the select config upon URB allocation failure.
1674 //
1675 if (m_NumInterfaces > 1 && maxNumPipes > 0) {
1677
1678 pSelectUrb = (PURB) FxPoolAllocate(GetDriverGlobals(),
1680 size
1681 );
1682
1683 if (pSelectUrb == NULL) {
1687 "Could not allocate a select interface URB, %!STATUS!", status);
1688 goto Done;
1689 }
1690
1691 RtlZeroMemory(pSelectUrb, size);
1692 }
1693
1694 //
1695 // Send the select config to the usb core
1696 //
1700
1701 FxFormatUsbRequest(request.m_TrueRequest, Urb, FxUrbType, m_USBDHandle);
1702 status = SubmitSync(request.m_TrueRequest, &options);
1703
1704 if (NT_SUCCESS(status)) {
1705 //
1706 // Save the config handle and store off all the pipes
1707 //
1708 m_ConfigHandle = Urb->UrbSelectConfiguration.ConfigurationHandle;
1709
1710 //
1711 // Initialize the first interface
1712 //
1713 pIface = &Urb->UrbSelectConfiguration.Interface;
1714
1717
1718 //
1719 // The interface now owns the array of pipes
1720 //
1721 pUsbInterface->SetConfiguredPipes(pPipeInfo[0].Pipes);
1722 pPipeInfo[0].Pipes = NULL;
1723 pPipeInfo[0].NumPipes = 0;
1724
1725 pUsbInterface->SetInfo(pIface);
1726
1727 //
1728 // Since this could be the only interface, set the index now, so if we
1729 // return the number of configured interfaces, it will be valid for the
1730 // single interface case.
1731 //
1732 intfIndex = 1;
1733
1734 //
1735 // If we have a more then one interface, we must select each of the addtional
1736 // interfaces after the select config because usbccgp (the generic parent
1737 // driver) didn't fill out all of the pipe info for IAD (interface
1738 // association descriptor) devices. The first interface is filled out
1739 // property, it is 2->N that are left blank.
1740 //
1741 // pSelectUrb can be equal to NULL and have more then one interface if
1742 // all interfaces have no pipes associated with them. In that case, we
1743 // still want to iterate over the remaining pipes so that we can
1744 // initialize our structures properly.
1745 //
1746 if (m_NumInterfaces > 1) {
1747 //
1748 // Loop over the interfaces again.
1749 //
1750 pCur = (PUCHAR) &Urb->UrbSelectConfiguration.Interface;
1752 pEnd = ((PUCHAR) Urb) + Urb->UrbSelectConfiguration.Hdr.Length;
1753
1754 //
1755 // Start at the 2nd one since the first is already selected
1756 //
1757 pCur += pIface->Length;
1758
1759 for ( ; pCur < pEnd; pCur += pIface->Length, intfIndex++) {
1760#pragma prefast(suppress: __WARNING_UNUSED_POINTER_ASSIGNMENT, "pIface is used in the for loop in many places. It looks like a false positive")
1762 ASSERT(pIface->NumberOfPipes <= maxNumPipes);
1763
1766
1767 //
1768 // Valid to have an interface with no pipes. If there are no
1769 // pipes, GET_SELECT_INTERFACE_REQUEST_SIZE will compute value
1770 // too small of a size to pass validation.
1771 //
1772 if (pIface->NumberOfPipes > 0) {
1773
1775 pSelectUrb,
1776 (USHORT) pIface->NumberOfPipes,
1777 pIface->AlternateSetting
1778 );
1779 irp = request.m_TrueRequest->GetSubmitFxIrp();
1781
1782 request.m_TrueRequest->ClearFieldsForReuse();
1783 FxFormatUsbRequest(request.m_TrueRequest,
1784 pSelectUrb,
1786 NULL);
1787
1788 status = SubmitSync(request.m_TrueRequest, &options);
1789 if (!NT_SUCCESS(status)) {
1792 "USB core failed Select Interface URB, %!STATUS!",
1793 status);
1794 goto Done;
1795 }
1796
1797 //
1798 // Copy the info back into the original select config URB
1799 //
1800
1801 RtlCopyMemory(pIface,
1802 &pSelectUrb->UrbSelectInterface.Interface,
1803 pSelectUrb->UrbSelectInterface.Interface.Length);
1804 }
1805
1806 //
1807 // Update the pointer to point to the new pipes with the pointer
1808 // to the pipes stored earlier.
1809 //
1810 ASSERT(pPipeInfo[intfIndex].NumPipes == pIface->NumberOfPipes);
1812
1813 //
1814 // The interface now owns the array of pipes
1815 //
1816 pUsbInterface->SetConfiguredPipes(pPipeInfo[intfIndex].Pipes);
1817 pPipeInfo[intfIndex].Pipes = NULL;
1818 pPipeInfo[intfIndex].NumPipes = 0;
1819
1820 //
1821 // SetInfo only after a successful select config so that we can
1822 // copy the USBD_PIPE_INFORMATION .
1823 //
1824 pUsbInterface->SetInfo(pIface);
1825 }
1826 }
1827
1828 if (NumConfiguredInterfaces != NULL) {
1829 *NumConfiguredInterfaces = intfIndex;
1830 }
1831 }
1832 else {
1835 "USB core failed Select Configuration, %!STATUS!", status);
1836 }
1837
1838Done:
1839 if (pSelectUrb != NULL) {
1840 FxPoolFree(pSelectUrb);
1841 pSelectUrb = NULL;
1842 }
1843
1844 if (pPipeInfo != NULL) {
1845 //
1846 // Free all arrays that may have been allocated
1847 //
1848 for (intfIndex = 0; intfIndex < m_NumInterfaces; intfIndex++) {
1849 //
1850 // We can have NumPipes == 0 and still have an allocated array, so
1851 // use the array != NULL as the check.
1852 //
1853 if (pPipeInfo[intfIndex].Pipes != NULL) {
1854 //
1855 // Delete any pipes that might have been created
1856 //
1857 for (iPipe = 0; iPipe < pPipeInfo[intfIndex].NumPipes; iPipe++) {
1858 if (pPipeInfo[intfIndex].Pipes[iPipe] != NULL) {
1859 pPipeInfo[intfIndex].Pipes[iPipe]->DeleteFromFailedCreate();
1860 pPipeInfo[intfIndex].Pipes[iPipe] = NULL;
1861 }
1862 }
1863
1864 //
1865 // Now free the array itself and clear out the count
1866 //
1867 FxPoolFree(pPipeInfo[intfIndex].Pipes);
1868 pPipeInfo[intfIndex].Pipes = NULL;
1869 pPipeInfo[intfIndex].NumPipes = 0;
1870 }
1871 }
1872
1873 FxPoolFree(pPipeInfo);
1874 pPipeInfo = NULL;
1875 }
1876
1877 return status;
1878}
1879
1883 VOID
1884 )
1885{
1888
1889 FxSyncRequest request(GetDriverGlobals(), NULL);
1891
1892 //
1893 // FxSyncRequest always succeesds for KM but can fail for UM.
1894 //
1895 status = request.Initialize();
1896 if (!NT_SUCCESS(status)) {
1898 "Failed to initialize FxSyncRequest");
1899 return status;
1900 }
1901
1902 status = request.m_TrueRequest->ValidateTarget(this);
1903 if (!NT_SUCCESS(status)) {
1904 return status;
1905 }
1906
1907 //
1908 // This will remove and free all interfaces and associated pipes
1909 //
1911
1912 RtlZeroMemory(&urb, sizeof(urb));
1913
1914#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "this annotation change in usb.h is communicated to usb team");
1915 UsbBuildSelectConfigurationRequest((PURB) &urb, sizeof(urb), NULL);
1916#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "this annotation change in usb.h is communicated to usb team");
1917 FxFormatUsbRequest(request.m_TrueRequest, (PURB) &urb, FxUrbTypeLegacy, NULL);
1918
1921
1922 status = SubmitSync(request.m_TrueRequest, &options);
1923
1924 return status;
1925}
1926
1931 __in PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
1932 __in_ecount(NumInterfaces) PUSB_INTERFACE_DESCRIPTOR* InterfaceDescriptors,
1933 __in ULONG NumInterfaces
1934 )
1935{
1936 PUSBD_INTERFACE_LIST_ENTRY pInterfaces;
1937 PURB urb;
1939 ULONG i, size;
1941
1943
1944 //
1945 // eventually size = sizeof(USBD_INTERFACE_LIST_ENTRY) * (NumInterfaces + 1)
1946 //
1947 status = RtlULongAdd(NumInterfaces, 1, &size);
1948 if (!NT_SUCCESS(status)) {
1949 return status;
1950 }
1951
1952 status = RtlULongMult(size, sizeof(USBD_INTERFACE_LIST_ENTRY), &size);
1953 if (!NT_SUCCESS(status)) {
1954 return status;
1955 }
1956
1957 for (i = 0; i < NumInterfaces; i++) {
1958 if (InterfaceDescriptors[i] == NULL) {
1960 }
1961 }
1962
1963 pInterfaces = (PUSBD_INTERFACE_LIST_ENTRY) FxPoolAllocate(
1966 size
1967 );
1968
1969 if (pInterfaces == NULL) {
1971
1974 "Could not allocate array of USBD_INTERFACE_LIST_ENTRY, %!STATUS!",
1975 status);
1976
1977 return status;
1978 }
1979
1980 RtlZeroMemory(pInterfaces, size);
1981
1982 for (i = 0; i < NumInterfaces; i++) {
1983 pInterfaces[i].InterfaceDescriptor = InterfaceDescriptors[i];
1984 }
1985
1986 if (ConfigurationDescriptor == NULL) {
1987 ConfigurationDescriptor = m_ConfigDescriptor;
1988 }
1989
1991 ConfigurationDescriptor,
1992 pInterfaces,
1994 if (urb == NULL) {
1996 }
1997 else {
1999 FxPoolFree(urb);
2000 urb = NULL;
2001 }
2002
2003 FxPoolFree(pInterfaces);
2004 pInterfaces = NULL;
2005
2006 return status;
2007}
2008
2012 )
2013{
2016 }
2017
2018 return NULL;
2019}
2020
2024 __in WDFUSBINTERFACE UsbInterface,
2026 )
2027{
2029
2033 (PVOID*) &pUsbInterface);
2034
2036
2037 return STATUS_SUCCESS;
2038}
2039
2043 )
2044{
2045 ULONG i;
2046
2047 for (i = 0; i < m_NumInterfaces; i++) {
2049 return m_Interfaces[i];
2050 }
2051 }
2052
2053 return NULL;
2054}
2055
2056VOID
2059 )
2060{
2061 SINGLE_LIST_ENTRY sentHead;
2062 LIST_ENTRY pendHead;
2063 ULONG iPipe;
2064 FxUsbPipe *pPipe;
2065 KIRQL irql;
2066
2067 sentHead.Next = NULL;
2068 InitializeListHead(&pendHead);
2069
2070 AcquireInterfaceIterationLock();
2071
2072 Lock(&irql);
2073 for (iPipe = 0; iPipe < UsbInterface->m_NumberOfConfiguredPipes; iPipe++) {
2074 BOOLEAN wait;
2075
2076 wait = FALSE;
2077 pPipe = UsbInterface->m_ConfiguredPipes[iPipe];
2078 pPipe->GotoRemoveState(
2080 &pendHead,
2081 &sentHead,
2082 TRUE,
2083 &wait);
2084 }
2085 Unlock(irql);
2086
2087 _CleanupPipesRequests(&pendHead, &sentHead);
2088
2089 for (iPipe = 0; iPipe < UsbInterface->m_NumberOfConfiguredPipes; iPipe++) {
2090 pPipe = UsbInterface->m_ConfiguredPipes[iPipe];
2091 pPipe->WaitForSentIoToComplete();
2092 }
2093
2094 UsbInterface->CleanUpAndDelete(FALSE);
2095
2096 ReleaseInterfaceIterationLock();
2097}
2098
2099VOID
2101 VOID
2102 )
2103{
2105 ULONG iInterface, iPipe;
2106
2107 for (iInterface = 0; iInterface < m_NumInterfaces; iInterface++) {
2108 pUsbInterface = m_Interfaces[iInterface];
2109
2111 for (iPipe = 0;
2113 iPipe++) {
2114
2115 if (pUsbInterface->m_ConfiguredPipes[iPipe] != NULL) {
2117 }
2118
2119 }
2120 }
2121 }
2122 FxIoTarget::CancelSentIo(); // __super call
2123}
2124
2128 __in_opt
2130 __out
2131 WDFMEMORY* UrbMemory,
2133 PURB* Urb
2134 )
2135{
2137 PURB urbLocal = NULL;
2139 FxUsbUrb * pUrb = NULL;
2140 WDFMEMORY hMemory;
2142
2143 //
2144 // Get the parent's globals if it is present, else use the ones for FxUsbDevice
2145 //
2148
2149 if (NT_SUCCESS(status)) {
2150
2152 Attributes->ParentObject,
2154 (PVOID*)&pParent,
2156
2160 "Urb must be parented to FxDevice or an IoAllocated Request");
2162 goto Done;
2163 }
2164
2165 }
2167
2169 pParent = this;
2171
2172 }
2173 else {
2174
2175 goto Done;
2176 }
2177
2179 if (!NT_SUCCESS(status)) {
2180 goto Done;
2181 }
2182
2184
2185 *UrbMemory = NULL;
2186
2187 status = USBD_UrbAllocate(m_USBDHandle, &urbLocal);
2188
2189 if (!NT_SUCCESS(status)) {
2190
2191 urbLocal = NULL;
2194 "USBDEVICE Must have been created with Client Contract Version Info, %!STATUS!",
2195 status);
2196
2197 goto Done;
2198
2199 }
2200
2201 pUrb = new(pFxDriverGlobals, Attributes)
2202 FxUsbUrb(pFxDriverGlobals, m_USBDHandle, urbLocal, sizeof(URB));
2203
2204 if (pUrb == NULL) {
2206 goto Done;
2207 }
2208
2209 urbLocal = NULL;
2210
2212
2213 if (!NT_SUCCESS(status)) {
2214 goto Done;
2215 }
2216
2217 *UrbMemory = hMemory;
2218
2219 if (Urb) {
2220 *Urb = (PURB) pUrb->GetBuffer();
2221 }
2222
2223Done:
2224
2225 if (!NT_SUCCESS(status)) {
2226
2227 if (pUrb) {
2228 pUrb->DeleteFromFailedCreate();
2229 }
2230
2231 if (urbLocal) {
2232 USBD_UrbFree(m_USBDHandle, urbLocal);
2233 }
2234
2235 }
2236
2237 return status;
2238}
2239
2243 __in_opt
2245 __in
2247 __out
2248 WDFMEMORY* UrbMemory,
2249 __deref_opt_out_bcount(GET_ISOCH_URB_SIZE(NumberOfIsochPackets))
2250 PURB* Urb
2251 )
2252{
2254 PURB urbLocal = NULL;
2256 FxUsbUrb * pUrb = NULL;
2257 WDFMEMORY hMemory;
2258 ULONG size;
2260
2261 //
2262 // Get the parent's globals if it is present, else use the ones for FxUsbDevice
2263 //
2266
2267 if (NT_SUCCESS(status)) {
2268
2270 Attributes->ParentObject,
2272 (PVOID*)&pParent,
2274
2278 "Urb must be parented to FxDevice or IoAllocated Request");
2280 goto Done;
2281 }
2282
2283 }
2285
2287 pParent = this;
2289
2290 }
2291 else {
2292
2293 goto Done;
2294 }
2295
2297 if (!NT_SUCCESS(status)) {
2298 goto Done;
2299 }
2300
2302
2303 *UrbMemory = NULL;
2304
2306
2307 if (!NT_SUCCESS(status)) {
2308
2309 urbLocal = NULL;
2312 "USBDEVICE Must have been created with Client Contract Version Info, %!STATUS!",
2313 status);
2314
2315 goto Done;
2316
2317 }
2318
2320
2321 pUrb = new(pFxDriverGlobals, Attributes)
2323
2324 if (pUrb == NULL) {
2326 goto Done;
2327 }
2328
2329 urbLocal = NULL;
2330
2332
2333 if (!NT_SUCCESS(status)) {
2334 goto Done;
2335 }
2336
2337 *UrbMemory = hMemory;
2338
2339 if (Urb) {
2340 *Urb = (PURB) pUrb->GetBuffer();
2341 }
2342
2343Done:
2344
2345 if (!NT_SUCCESS(status)) {
2346
2347 if (pUrb) {
2348 pUrb->DeleteFromFailedCreate();
2349 }
2350
2351 if (urbLocal) {
2352 USBD_UrbFree(m_USBDHandle, urbLocal);
2353 }
2354
2355 }
2356
2357 return status;
2358}
2359
2360BOOLEAN
2363 )
2364/*++
2365
2366Routine Description:
2367 This routine determines if the Object being passed is guranteed to be disposed on a
2368 Pnp remove operation.
2369
2370 The object will be disposed on Pnp remove operation if it is a somewhere in the child
2371 tree of the FxDevice assocaited with this FxUsbDevice object, or in the child tree of an
2372 Io Allocated Request.
2373
2374Arguments:
2375
2376 Object - The Object being checked
2377
2378Return Value:
2379
2380 TRUE if the Object is guranteed to be disposed on a pnp remove operation
2381 FALSE otherwise.
2382
2383 --*/
2384{
2385 FxObject * obj;
2386 FxObject * parent;
2387 BOOLEAN isObjectDisposedOnRemove = FALSE;
2388
2389 obj = Object;
2390
2391 //
2392 // By adding a reference now, we simulate what GetParentObjectReferenced
2393 // does later, thus allowing simple logic on when/how to release the
2394 // reference on exit.
2395 //
2396 obj->ADDREF(Object);
2397
2398 while (obj != NULL) {
2399
2400 if (obj == (FxObject*) m_Device) {
2401
2402 isObjectDisposedOnRemove = TRUE;
2403 break;
2404 }
2405
2407
2409 if (request->IsAllocatedFromIo()) {
2410
2411 isObjectDisposedOnRemove = TRUE;
2412 break;
2413 }
2414 }
2415
2416 parent = obj->GetParentObjectReferenced(Object);
2417
2418 //
2419 // Release the reference previously taken by the top of the function
2420 // or GetParentObjectReferenced in a previous pass in the loop.
2421 //
2422 obj->RELEASE(Object);
2423 obj = parent;
2424 }
2425
2426 if (obj != NULL) {
2427
2428 //
2429 // Release the reference previously taken by the top of the function
2430 // or GetParentObjectReferenced in a last pass in the loop.
2431 //
2432 obj->RELEASE(Object);
2433 }
2434
2435 return isObjectDisposedOnRemove;
2436}
2437
2441 )
2442/*++
2443
2444Routine Description:
2445 This routine essentially determines whether this routine can use a urb allocated by
2446 the USBD_xxxUrbAllocate APIs
2447
2448 The USBD_xxxUrbAllocate APIs are only used for those requests that could be disposed at the
2449 time the client driver devnode is being removed.
2450
2451 If we cannot make that gurantee about that request, FxUrbTypeLegacy is returned and the
2452 USBD_xxxUrbAllocate api's must not be used to allocate an Urb.
2453
2454 Else FxUrbTypeUsbdAllocated is returned.
2455
2456Arguments:
2457
2458 Request - FxRequest
2459
2460Return Value:
2461
2462 FxUrbTypeUsbdAllocated, or FxUrbTypeLegacy
2463
2464 --*/
2465{
2466 if (m_UrbType == FxUrbTypeLegacy) {
2467 return FxUrbTypeLegacy;
2468 }
2469
2470 if (Request->IsAllocatedFromIo()) {
2472 }
2473
2476 }
2477
2478 return FxUrbTypeLegacy;
2479}
2480
unsigned char BOOLEAN
struct outqueuenode * head
Definition: adnsresfilter.c:66
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
virtual VOID Stop(__in WDF_IO_TARGET_SENT_IO_ACTION Action)
Definition: fxiotarget.cpp:748
VOID CancelSentIo(VOID)
_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)
_Must_inspect_result_ NTSTATUS Init(__in CfxDeviceBase *Device)
virtual BOOLEAN Dispose(VOID)
Definition: fxiotarget.cpp:154
WDF_IO_TARGET_STATE m_State
Definition: fxiotarget.hpp:928
VOID CompletePendedRequest(__in FxRequestBase *Request)
Definition: fxiotarget.cpp:508
VOID CompletePendedRequestList(__in PLIST_ENTRY RequestListHead)
Definition: fxiotarget.cpp:520
_Must_inspect_result_ NTSTATUS FormatInternalIoctlOthersRequest(__in FxRequestBase *Request, __in ULONG Ioctl, __in FxRequestBuffer *Buffers)
static VOID _CancelSentRequests(__in PSINGLE_LIST_ENTRY RequestListHead)
Definition: fxiotarget.cpp:550
VOID SubmitPendedRequest(__in FxRequestBase *Request)
Definition: fxiotarget.cpp:206
_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)
virtual VOID Purge(__in WDF_IO_TARGET_PURGE_IO_ACTION Action)
Definition: fxiotarget.cpp:918
virtual _Must_inspect_result_ NTSTATUS Start(VOID)
Definition: fxiotarget.cpp:282
virtual VOID WaitForSentIoToComplete(VOID)
Definition: fxiotarget.hpp:676
Definition: fxirp.hpp:28
VOID Reuse(__in NTSTATUS Status=STATUS_SUCCESS)
Definition: fxirpum.cpp:661
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
CfxDevice * m_Device
Definition: fxobject.hpp:329
CfxDeviceBase * m_DeviceBase
Definition: fxobject.hpp:328
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
virtual BOOLEAN Dispose(VOID)
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
static __inline FxRequestBase * _FromListEntry(__in PLIST_ENTRY Entry)
__inline FxIoTarget * GetTarget(VOID)
_Must_inspect_result_ NTSTATUS CreateInterfaces(VOID)
virtual VOID Purge(__in WDF_IO_TARGET_PURGE_IO_ACTION Action)
virtual BOOLEAN Dispose(VOID)
WINUSB_INTERFACE_HANDLE m_WinUsbHandle
VOID PipesGotoRemoveState(__in BOOLEAN ForceRemovePipes)
USBD_PIPE_HANDLE m_ControlPipe
VOID GetInformation(__out PWDF_USB_DEVICE_INFORMATION Information)
_Must_inspect_result_ NTSTATUS SelectConfig(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PURB Urb, __in FX_URB_TYPE FxUrbType, __out_opt PUCHAR NumConfiguredInterfaces)
virtual VOID Stop(__in WDF_IO_TARGET_SENT_IO_ACTION Action)
VOID CleanupInterfacePipesAndDelete(__in FxUsbInterface *UsbInterface)
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
_Must_inspect_result_ NTSTATUS FormatCycleRequest(__in FxRequestBase *Request)
virtual _Must_inspect_result_ NTSTATUS Start(VOID)
_Must_inspect_result_ NTSTATUS IsConnected(VOID)
PINTERFACE_DEREFERENCE m_BusInterfaceDereference
PUSB_BUSIFFN_QUERY_BUS_TIME m_QueryBusTime
USBD_VERSION_INFORMATION m_UsbdVersionInformation
_Must_inspect_result_ NTSTATUS GetPortStatus(__out PULONG PortStatus)
USBD_HANDLE m_USBDHandle
IWudfFile * m_pHostTargetFile
~FxUsbDevice(VOID)
VOID RemoveDeletedInterface(__in FxUsbInterface *Interface)
ULONG GetDefaultMaxTransferSize(VOID)
BOOLEAN IsObjectDisposedOnRemove(__in FxObject *Object)
FxUsbDevice(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
static VOID _CleanupPipesRequests(__in PLIST_ENTRY PendHead, __in PSINGLE_LIST_ENTRY SentHead)
__checkReturn NTSTATUS CreateUrb(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out WDFMEMORY *UrbMemory, __deref_opt_out_bcount(sizeof(URB)) PURB *Urb)
_Must_inspect_result_ NTSTATUS CyclePort(VOID)
friend FxUsbPipe
FxUsbInterface * GetInterfaceFromIndex(__in UCHAR InterfaceIndex)
_Must_inspect_result_ NTSTATUS GetConfigDescriptor(__out PVOID ConfigDescriptor, __inout PUSHORT ConfigDescriptorLength)
PUSB_CONFIGURATION_DESCRIPTOR m_ConfigDescriptor
_Must_inspect_result_ NTSTATUS SelectConfigInterfaces(__in PWDF_OBJECT_ATTRIBUTES PipesAttributes, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, __in_ecount(NumInterfaces) PUSB_INTERFACE_DESCRIPTOR *InterfaceDescriptors, __in ULONG NumInterfaces)
FX_URB_TYPE m_UrbType
BOOLEAN IsEnabled(VOID)
UCHAR m_NumInterfaces
friend FxUsbInterface
VOID CancelSentIo(VOID)
ULONG m_HcdPortCapabilities
__checkReturn NTSTATUS CreateIsochUrb(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG NumberOfIsochPackets, __out WDFMEMORY *UrbMemory, __deref_opt_out_bcount(GET_ISOCH_URB_SIZE(NumberOfIsochPackets)) PURB *Urb)
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 Deconfig(VOID)
FxUsbInterface ** m_Interfaces
FxUsbInterface * GetInterfaceFromNumber(__in UCHAR InterfaceNumber)
_Must_inspect_result_ NTSTATUS SelectConfigDescriptor(__in PWDF_OBJECT_ATTRIBUTES PipeAttributes, __in PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params)
BOOLEAN m_OnUSBD
USBD_CONFIGURATION_HANDLE m_ConfigHandle
BOOLEAN m_MismatchedInterfacesInConfigDescriptor
FxUsbPipe ** m_ConfiguredPipes
VOID FormatSelectSettingUrb(__in_bcount(GET_SELECT_INTERFACE_REQUEST_SIZE(NumEndpoints)) PURB Urb, __in USHORT NumEndpoints, __in UCHAR SettingNumber)
VOID CleanUpAndDelete(__in BOOLEAN ClearDestroyCallback)
VOID SetConfiguredPipes(__in FxUsbPipe **ppPipes)
UCHAR GetInterfaceNumber(VOID)
BOOLEAN IsInterfaceConfigured(VOID)
UCHAR m_NumberOfConfiguredPipes
VOID SetInfo(__in PUSBD_INTERFACE_INFORMATION Interface)
VOID SetNumConfiguredPipes(__in UCHAR NumberOfPipes)
VOID GotoPurgeState(__in WDF_IO_TARGET_PURGE_IO_ACTION Action, __in PLIST_ENTRY PendedRequestListHead, __in PSINGLE_LIST_ENTRY SentRequestListHead, __out PBOOLEAN Wait, __in BOOLEAN LockSelf)
Definition: fxusbpipe.cpp:1296
virtual VOID GotoStopState(__in WDF_IO_TARGET_SENT_IO_ACTION Action, __in PSINGLE_LIST_ENTRY SentRequestListHead, __out PBOOLEAN Wait, __in BOOLEAN LockSelf)
Definition: fxusbpipe.cpp:1219
virtual VOID GotoRemoveState(__in WDF_IO_TARGET_STATE NewState, __in PLIST_ENTRY PendedRequestListHead, __in PSINGLE_LIST_ENTRY SentRequestListHead, __in BOOLEAN Lock, __out PBOOLEAN Wait)
Definition: fxusbpipe.cpp:1369
virtual VOID WaitForSentIoToComplete(VOID)
Definition: fxusbpipe.cpp:1421
virtual _Must_inspect_result_ NTSTATUS GotoStartState(__in PLIST_ENTRY RequestListHead, __in BOOLEAN Lock=TRUE)
Definition: fxusbpipe.cpp:1135
USBD_HANDLE m_USBDHandle
virtual BOOLEAN Dispose(VOID)
FxUsbUrb(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USBD_HANDLE USBDHandle, __in_bcount(BufferSize) PVOID Buffer, __in size_t BufferSize)
virtual size_t GetBufferSize(VOID)=0
virtual PVOID GetBuffer(VOID)=0
static __inline VOID MxUnlockPages(__in PMDL Mdl)
Definition: mxgeneralkm.h:357
static __inline KIRQL MxGetCurrentIrql()
Definition: mxgeneralkm.h:86
#define __out_opt
Definition: dbghelp.h:65
#define __in_ecount(x)
Definition: dbghelp.h:47
#define __in
Definition: dbghelp.h:35
#define __in_bcount(x)
Definition: dbghelp.h:41
#define __inout
Definition: dbghelp.h:50
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define BufferSize
Definition: mmc.h:75
#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
r parent
Definition: btrfs.c:3010
KIRQL irql
Definition: wave.h:1
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Device, FX_TYPE_DEVICE,(PVOID *)&pDevice, &pFxDriverGlobals)
PFX_DRIVER_GLOBALS pFxDriverGlobals
FxIoTarget * pTarget
Definition: fxdeviceapi.cpp:97
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Fdo, FX_TYPE_DEVICE,(PVOID *)&pFdo)
SINGLE_LIST_ENTRY * pCur
PSINGLE_LIST_ENTRY ple
FxRequest * pRequest
FxObject * pParent
Definition: fxdpcapi.cpp:86
__inline BOOLEAN FxObjectCheckType(__in FxObject *Object, __in WDFTYPE Type)
Definition: fxhandle.h:240
WDFMEMORY hMemory
#define FxPointerNotNull(FxDriverGlobals, Ptr)
Definition: fxmacros.hpp:253
VOID __inline FxMdlFree(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PMDL Mdl)
Definition: fxmdl.h:60
@ ObjectDoNotLock
Definition: fxobject.hpp:128
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
#define RtlSizeTToULong
PINTERFACE pInterface
FxIrp * irp
#define FX_REQUEST_NUM_OTHER_PARAMS
@ FX_RCT_USB_CONTROL_REQUEST
@ FX_RCT_USB_STRING_REQUEST
@ FX_TYPE_USB_INTERFACE
Definition: fxtypes.h:104
@ FX_TYPE_OBJECT
Definition: fxtypes.h:45
@ FX_TYPE_REQUEST
Definition: fxtypes.h:53
@ FX_TYPE_IO_TARGET_USB_DEVICE
Definition: fxtypes.h:102
@ FxUrbTypeLegacy
Definition: fxusbdevice.hpp:27
@ FxUrbTypeUsbdAllocated
Definition: fxusbdevice.hpp:28
enum _FX_URB_TYPE FX_URB_TYPE
FxUsbInterface * pUsbInterface
return pUsbInterface GetInterfaceNumber()
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
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
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:42
#define UCHAR_MAX
Definition: limits.h:25
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define for
Definition: utility.h:88
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:522
unsigned short USHORT
Definition: pedump.c:61
#define __checkReturn
Definition: sal_old.h:113
#define __deref_opt_out_bcount(size)
Definition: sal_old.h:184
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
virtual VOID ReleaseAndRestore(__in FxRequestBase *Request)
WDF_REQUEST_COMPLETION_PARAMS m_CompletionParams
IFxMemory * m_RequestMemory
_URB_CONTROL_TRANSFER * m_Urb
Definition: fxusbdevice.hpp:86
virtual VOID ReleaseAndRestore(__in FxRequestBase *Request)
FxUsbDeviceControlContext(__in FX_URB_TYPE FxUrbType)
Definition: fxusbdevice.cpp:40
USBD_STATUS GetUsbdStatus(VOID)
_URB_CONTROL_TRANSFER m_UrbLegacy
Definition: fxusbdevice.hpp:81
virtual VOID CopyParameters(__in FxRequestBase *Request)
__checkReturn NTSTATUS AllocateUrb(__in USBD_HANDLE USBDHandle)
Definition: fxusbdevice.cpp:70
virtual VOID Dispose(VOID)
Definition: fxusbdevice.cpp:92
virtual VOID Dispose(VOID)
FxUsbDeviceStringContext(__in FX_URB_TYPE FxUrbType)
VOID SetUrbInfo(__in UCHAR StringIndex, __in USHORT LangID)
PUSB_STRING_DESCRIPTOR m_StringDescriptor
virtual VOID CopyParameters(__in FxRequestBase *Request)
_Must_inspect_result_ NTSTATUS AllocateDescriptor(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in size_t BufferSize)
USBD_STATUS GetUsbdStatus(VOID)
__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)
WDF_USB_REQUEST_COMPLETION_PARAMS m_UsbParameters
virtual VOID CopyParameters(__in FxRequestBase *Request)
PINTERFACE Interface
Definition: iotypes.h:3250
Definition: typedefs.h:120
Definition: ntbasedef.h:640
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:641
struct _UMURB_CONTROL_TRANSFER UmUrbControlTransfer
Definition: umusb.h:200
struct _UMURB_DESCRIPTOR_REQUEST UmUrbDescriptorRequest
Definition: umusb.h:245
struct _URB_HEADER Hdr
Definition: usb.h:341
ULONG TransferBufferLength
Definition: usb.h:470
struct _URB_HEADER Hdr
Definition: usb.h:467
Definition: usb.h:529
struct _URB_SELECT_INTERFACE UrbSelectInterface
Definition: usb.h:532
Definition: usbdlib.h:7
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: usbdlib.h:8
struct _WDF_USB_REQUEST_COMPLETION_PARAMS::@4014::@4015 DeviceString
union _WDF_USB_REQUEST_COMPLETION_PARAMS::@4014 Parameters
struct _WDF_USB_REQUEST_COMPLETION_PARAMS::@4014::@4016 DeviceControlTransfer
Definition: match.c:390
Definition: http.c:7252
Definition: devices.h:37
Definition: tftpd.h:86
Definition: ps.c:97
#define GetHandle(h)
Definition: treelist.c:116
uint32_t * PULONG
Definition: typedefs.h:59
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_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _USB_STRING_DESCRIPTOR * PUSB_STRING_DESCRIPTOR
struct _USB_INTERFACE_DESCRIPTOR * PUSB_INTERFACE_DESCRIPTOR
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
struct _URB * PURB
#define USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE
Definition: usb.h:236
LONG USBD_STATUS
Definition: usb.h:165
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
NTSTATUS USBD_UrbAllocate(_In_ USBD_HANDLE USBDHandle, _Outptr_result_bytebuffer_(sizeof(URB)) PURB *Urb)
Definition: usbdex.c:59
NTSTATUS USBD_IsochUrbAllocate(_In_ USBD_HANDLE USBDHandle, _In_ ULONG NumberOfIsochPacket, _Outptr_result_bytebuffer_(sizeof(struct _URB_ISOCH_TRANSFER)+(NumberOfIsochPackets *sizeof(USBD_ISO_PACKET_DESCRIPTOR)) - sizeof(USBD_ISO_PACKET_DESCRIPTOR)) PURB *Urb)
Definition: usbdex.c:69
VOID USBD_UrbFree(_In_ USBD_HANDLE USBDHandle, _In_ PURB Urb)
Definition: usbdex.c:83
#define UsbBuildSelectConfigurationRequest(urb, length, configurationDescriptor)
Definition: usbdlib.h:53
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ ULONG _In_ ULONG _Out_ USBD_HANDLE * USBDHandle
Definition: usbdlib.h:278
VOID USBD_CloseHandle(_In_ USBD_HANDLE USBDHandle)
Definition: usbdex.c:51
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
Definition: usbdlib.h:117
struct _USBD_INTERFACE_LIST_ENTRY * PUSBD_INTERFACE_LIST_ENTRY
_In_ PIO_STACK_LOCATION _In_ PURB Urb
Definition: usbdlib.h:267
#define GET_ISO_URB_SIZE(n)
Definition: usbdlib.h:125
_In_ PVOID _In_ LONG InterfaceNumber
Definition: usbdlib.h:169
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53
#define USBD_PORT_ENABLED
Definition: usbioctl.h:41
#define USBD_PORT_CONNECTED
Definition: usbioctl.h:42
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44
PUSB_COMMON_DESCRIPTOR FxUsbFindDescriptorType(__in PVOID Buffer, __in size_t BufferLength, __in PVOID Start, __in LONG DescriptorType)
Definition: usbutil.cpp:176
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: usbutil.cpp:209
NTSTATUS FxUsbValidateConfigDescriptorHeaders(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, __in size_t ConfigDescriptorLength)
Definition: usbutil.cpp:113
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
@ FxUsbValidateDescriptorOpAtLeast
Definition: usbutil.hpp:128
BOOLEAN __inline FxBitArraySet(__inout_xcount((BitNumber/sizeof(UCHAR))+1) PUCHAR BitArray, __in UCHAR BitNumber)
Definition: usbutil.hpp:9
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
FORCEINLINE LONGLONG WDF_REL_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:62
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
enum _WDF_IO_TARGET_PURGE_IO_ACTION WDF_IO_TARGET_PURGE_IO_ACTION
@ WdfIoTargetLeaveSentIoPending
Definition: wdfiotarget.h:73
enum _WDF_IO_TARGET_SENT_IO_ACTION WDF_IO_TARGET_SENT_IO_ACTION
@ WdfIoTargetDeleted
Definition: wdfiotarget.h:57
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
@ WdfIoTargetPurgeIo
Definition: wdfiotarget.h:79
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
FORCEINLINE VOID WDF_REQUEST_SEND_OPTIONS_INIT(_Out_ PWDF_REQUEST_SEND_OPTIONS Options, _In_ ULONG Flags)
Definition: wdfrequest.h:409
@ WDF_REQUEST_SEND_OPTION_IGNORE_TARGET_STATE
Definition: wdfrequest.h:110
_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
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
#define STATUS_WDF_PARENT_NOT_SPECIFIED
Definition: wdfstatus.h:252
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105
_In_ WDFUSBINTERFACE UsbInterface
Definition: wdfusb.h:2276
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_ WDFREQUEST _In_ WDFMEMORY UrbMemory
Definition: wdfusb.h:1576
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID ConfigDescriptor
Definition: wdfusb.h:1036
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ ULONG NumberOfIsochPackets
Definition: wdfusb.h:1703
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID _Inout_ PUSHORT ConfigDescriptorLength
Definition: wdfusb.h:1040
_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
@ WdfUsbRequestTypeDeviceString
Definition: wdfusb.h:89
_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
_In_ WDFUSBDEVICE _In_ UCHAR InterfaceIndex
Definition: wdfusb.h:2462
_Must_inspect_result_ _In_ WDFUSBINTERFACE _In_opt_ PWDF_OBJECT_ATTRIBUTES PipesAttributes
Definition: wdfusb.h:2390
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define SAFE_RELEASE(p)
unsigned char UCHAR
Definition: xmlstorage.h:181