ReactOS 0.4.16-dev-303-g11d5cb8
urb.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS USB Port Driver
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: USBPort URB functions
5 * COPYRIGHT: Copyright 2017 Vadim Galyant <vgal@rambler.ru>
6 */
7
8#include "usbport.h"
9
10#define NDEBUG
11#include <debug.h>
12
13#define NDEBUG_USBPORT_URB
14#include "usbdebug.h"
15
19{
21
22 DPRINT_URB("USBPORT_HandleGetConfiguration: Urb - %p\n", Urb);
23
25 &Urb->UrbControlGetConfigurationRequest.Reserved1;
26
27 SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
29 SetupPacket->wValue.W = 0;
30 SetupPacket->wIndex.W = 0;
31 SetupPacket->wLength = Urb->UrbControlGetConfigurationRequest.TransferBufferLength;
32
33 Urb->UrbControlGetConfigurationRequest.Reserved0 |= USBD_TRANSFER_DIRECTION_IN; // 1;
34 Urb->UrbControlGetConfigurationRequest.Reserved0 |= USBD_SHORT_TRANSFER_OK; // 2
35
37
39
40 return STATUS_PENDING;
41}
42
46 IN PIRP Irp,
47 IN PURB Urb)
48{
51 ULONG FrameNumber;
53
54 FdoExtension = FdoDevice->DeviceExtension;
55 Packet = &FdoExtension->MiniPortInterface->Packet;
56
57 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
58 FrameNumber = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
59 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
60
61 Urb->UrbGetCurrentFrameNumber.FrameNumber = FrameNumber;
62
63 DPRINT_URB("USBPORT_HandleGetCurrentFrame: FrameNumber - %p\n",
64 FrameNumber);
65
67}
68
72 IN PIRP Irp,
73 IN PURB Urb)
74{
75 PUSBPORT_ENDPOINT Endpoint;
79
80 DPRINT_URB("USBPORT_AbortPipe: ... \n");
81
82 PipeHandle = Urb->UrbPipeRequest.PipeHandle;
83 DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
84
86 {
88 {
89 Endpoint = PipeHandle->Endpoint;
90
92
93 Irp->IoStatus.Status = Status;
95
96 USBPORT_AbortEndpoint(FdoDevice, Endpoint, Irp);
97
98 return Status;
99 }
100
102 }
103 else
104 {
107 }
108
109 return Status;
110}
111
113NTAPI
115 IN PIRP Irp,
116 IN PURB Urb)
117{
121 PUSBPORT_ENDPOINT Endpoint;
123
124 DPRINT_URB("USBPORT_ResetPipe: ... \n");
125
126 FdoExtension = FdoDevice->DeviceExtension;
127 Packet = &FdoExtension->MiniPortInterface->Packet;
128
129 PipeHandle = Urb->UrbPipeRequest.PipeHandle;
130
131 if (!USBPORT_ValidatePipeHandle((PUSBPORT_DEVICE_HANDLE)Urb->UrbHeader.UsbdDeviceHandle,
132 PipeHandle))
133 {
135 }
136
137 Endpoint = PipeHandle->Endpoint;
138
139 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
140
141 if (IsListEmpty(&Endpoint->TransferList))
142 {
143 if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_NOT_ISO_TRANSFER)
144 {
145 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
146
147 Packet->SetEndpointDataToggle(FdoExtension->MiniPortExt,
148 Endpoint + 1,
149 0);
150
152 }
153
155 }
156 else
157 {
159 }
160
162
163 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
164
165 Packet->SetEndpointStatus(FdoExtension->MiniPortExt,
166 Endpoint + 1,
168
171
172 return Status;
173}
174
176NTAPI
178 IN PIRP Irp,
179 IN PURB Urb)
180{
183 USBD_STATUS USBDStatus;
184 PUSBPORT_ENDPOINT Endpoint;
187
188 DPRINT_URB("USBPORT_ClearStall: ... \n");
189
190 PipeHandle = Urb->UrbPipeRequest.PipeHandle;
191 DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
192
194 {
197 }
198
199 Endpoint = PipeHandle->Endpoint;
200
202
203 SetupPacket.bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
205 SetupPacket.wValue.W = 0;
207 SetupPacket.wLength = 0;
208
210 FdoDevice,
212 NULL,
213 0,
214 NULL,
215 &USBDStatus);
216
217 Status = USBPORT_USBDStatusToNtStatus(Urb, USBDStatus);
218
219 return Status;
220}
221
223NTAPI
225 IN PIRP Irp,
226 IN PURB Urb)
227{
230 PUSBPORT_ENDPOINT Endpoint;
231 ULONG EndpointState;
233
234 DPRINT_URB("USBPORT_SyncResetPipeAndClearStall: ... \n");
235
236 ASSERT(Urb->UrbHeader.UsbdDeviceHandle);
237 ASSERT(Urb->UrbHeader.Length == sizeof(struct _URB_PIPE_REQUEST));
238 ASSERT(Urb->UrbPipeRequest.PipeHandle);
239
240 DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
241 PipeHandle = Urb->UrbPipeRequest.PipeHandle;
242
244 {
247 }
248
250 {
252 }
253
254 Endpoint = PipeHandle->Endpoint;
255 InterlockedIncrement(&DeviceHandle->DeviceHandleLock);
256
258 {
259 Urb->UrbHeader.UsbdFlags |= USBD_FLAG_NOT_ISO_TRANSFER;
260 Status = USBPORT_ClearStall(FdoDevice, Irp, Urb);
261 }
262 else
263 {
265 }
266
267 if (NT_SUCCESS(Status))
268 {
269 Status = USBPORT_ResetPipe(FdoDevice, Irp, Urb);
270
272 {
273 while (TRUE)
274 {
276 &Endpoint->EndpointOldIrql);
277
278 EndpointState = USBPORT_GetEndpointState(Endpoint);
279
280 if (EndpointState == USBPORT_ENDPOINT_PAUSED &&
281 IsListEmpty(&Endpoint->TransferList))
282 {
285 }
286
288 Endpoint->EndpointOldIrql);
289
290 if (EndpointState == USBPORT_ENDPOINT_ACTIVE)
291 {
292 break;
293 }
294
295 USBPORT_Wait(FdoDevice, 1);
296 }
297 }
298 }
299
300 InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
301
302 return Status;
303}
304
306NTAPI
308{
310
311 DPRINT_URB("USBPORT_HandleSetOrClearFeature: Urb - %p\n", Urb);
312
314 &Urb->UrbControlFeatureRequest.Reserved0;
315
316 SetupPacket->wLength = 0;
317 Urb->UrbControlFeatureRequest.Reserved3 = 0; // TransferBufferLength
318
319 SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
320
321 switch (Urb->UrbHeader.Function)
322 {
324 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n");
326 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
327 break;
328
330 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE\n");
332 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
333 break;
334
336 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE\n");
338 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
339 break;
340
342 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT\n");
344 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
345 break;
346
348 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT\n");
350 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
351 break;
352
354 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n");
356 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
357 break;
358
360 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE\n");
362 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
363 break;
364
366 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE\n");
368 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
369 break;
370 }
371
372 Urb->UrbControlFeatureRequest.Reserved2 &= ~USBD_TRANSFER_DIRECTION_IN;
373 Urb->UrbControlFeatureRequest.Reserved2 |= USBD_SHORT_TRANSFER_OK;
374
376
378
379 return STATUS_PENDING;
380}
381
383NTAPI
385{
386 PUSBPORT_ENDPOINT Endpoint;
387
388 DPRINT_URB("USBPORT_HandleDataTransfers: Urb - %p\n", Urb);
389
390 Endpoint = ((PUSBPORT_PIPE_HANDLE)
391 (Urb->UrbBulkOrInterruptTransfer.PipeHandle))->Endpoint;
392
394 {
396 {
397 Urb->UrbBulkOrInterruptTransfer.TransferFlags &= ~USBD_TRANSFER_DIRECTION_IN;
398 }
399 else
400 {
401 Urb->UrbBulkOrInterruptTransfer.TransferFlags |= USBD_TRANSFER_DIRECTION_IN;
402 }
403 }
404
406
407 return STATUS_PENDING;
408}
409
411NTAPI
413 IN PURB Urb)
414{
417
419 &Urb->UrbControlDescriptorRequest.Reserved1;
420
421 SetupPacket->bmRequestType.B = 0;
422 SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
424 SetupPacket->wLength = Urb->UrbControlDescriptorRequest.TransferBufferLength;
425 SetupPacket->wValue.W = 0;
426
427 switch (Urb->UrbHeader.Function)
428 {
430 DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_DEVICE\n");
431 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
432 break;
433
435 DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_INTERFACE\n");
436 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
437 break;
438
440 DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_ENDPOINT\n");
441 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
442 break;
443
445 DPRINT_URB("USBPORT_HandleGetStatus: URB_FUNCTION_GET_STATUS_FROM_OTHER\n");
446 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
447 break;
448 }
449
450 if (SetupPacket->wLength == 2)
451 {
452 Urb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
453
454 if (SetupPacket->bmRequestType.Dir)
455 Urb->UrbControlTransfer.TransferFlags |= USBD_TRANSFER_DIRECTION_IN;
456 else
457 Urb->UrbControlTransfer.TransferFlags &= ~USBD_TRANSFER_DIRECTION_IN;
458
459 //USBPORT_DumpingSetupPacket(SetupPacket);
460
462
464 }
465 else
466 {
469
470 DPRINT1("USBPORT_HandleGetStatus: Bad wLength\n");
472 }
473
474 return Status;
475}
476
478NTAPI
480 IN PURB Urb)
481{
483
484 /*
485 Specifies a value, from 4 to 31 inclusive,
486 that becomes part of the request type code in the USB-defined setup packet.
487 This value is defined by USB for a class request or the vendor for a vendor request.
488 */
489
491 &Urb->UrbControlDescriptorRequest.Reserved1;
492
493 SetupPacket->bmRequestType.Dir = USBD_TRANSFER_DIRECTION_FLAG
494 (Urb->UrbControlTransfer.TransferFlags);
495
496 SetupPacket->wLength = Urb->UrbControlDescriptorRequest.TransferBufferLength;
497
498 Urb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
499
500 switch (Urb->UrbHeader.Function)
501 {
503 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_DEVICE\n");
504 SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
505 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
506 break;
507
509 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_INTERFACE\n");
510 SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
511 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
512 break;
513
515 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_ENDPOINT\n");
516 SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
517 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
518 break;
519
521 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_DEVICE\n");
522 SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
523 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
524 break;
525
527 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_INTERFACE\n");
528 SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
529 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
530 break;
531
533 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_ENDPOINT\n");
534 SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
535 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
536 break;
537
539 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_CLASS_OTHER\n");
540 SetupPacket->bmRequestType.Type = BMREQUEST_CLASS;
541 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
542 break;
543
545 DPRINT_URB("USBPORT_HandleVendorOrClass: URB_FUNCTION_VENDOR_OTHER\n");
546 SetupPacket->bmRequestType.Type = BMREQUEST_VENDOR;
547 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_OTHER;
548 break;
549 }
550
552
554
555 return STATUS_PENDING;
556}
557
559NTAPI
561 IN PURB Urb)
562{
564
566 &Urb->UrbControlDescriptorRequest.Reserved1;
567
568 SetupPacket->wLength = Urb->UrbControlDescriptorRequest.TransferBufferLength;
569 SetupPacket->bmRequestType.B = 0; // Clear bmRequestType
570 SetupPacket->bmRequestType.Type = BMREQUEST_STANDARD;
571
572 switch (Urb->UrbHeader.Function)
573 {
575 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n");
577 SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
578 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
579 break;
580
582 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE\n");
584 SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
585 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
586 break;
587
589 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT\n");
591 SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
592 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
593 break;
594
596 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT\n");
598 SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
599 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
600 break;
601
603 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n");
605 SetupPacket->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
606 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
607 break;
608
610 DPRINT_URB("USBPORT_HandleGetSetDescriptor: URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE\n");
612 SetupPacket->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
613 SetupPacket->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
614 break;
615 }
616
617 Urb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
618
619 if (SetupPacket->bmRequestType.Dir)
620 Urb->UrbControlTransfer.TransferFlags |= USBD_TRANSFER_DIRECTION_IN;
621 else
622 Urb->UrbControlTransfer.TransferFlags &= ~USBD_TRANSFER_DIRECTION_IN;
623
625
627
628 return STATUS_PENDING;
629}
630
632NTAPI
634{
635 struct _URB_CONTROL_TRANSFER *UrbRequest;
636 PMDL Mdl;
637
638 DPRINT_URB("USBPORT_ValidateTransferParametersURB: Urb - %p\n", Urb);
639
640 UrbRequest = &Urb->UrbControlTransfer;
641
642 if (UrbRequest->TransferBuffer == NULL &&
643 UrbRequest->TransferBufferMDL == NULL &&
644 UrbRequest->TransferBufferLength > 0)
645 {
646 DPRINT1("USBPORT_ValidateTransferParametersURB: Not valid parameter\n");
649 }
650
651 if ((UrbRequest->TransferBuffer != NULL) &&
652 (UrbRequest->TransferBufferMDL != NULL) &&
653 UrbRequest->TransferBufferLength == 0)
654 {
655 DPRINT1("USBPORT_ValidateTransferParametersURB: Not valid parameter\n");
658 }
659
660 if (UrbRequest->TransferBuffer != NULL &&
661 UrbRequest->TransferBufferMDL == NULL &&
662 UrbRequest->TransferBufferLength != 0)
663 {
664 DPRINT_URB("USBPORT_ValidateTransferParametersURB: TransferBuffer - %p, TransferBufferLength - %x\n",
665 UrbRequest->TransferBuffer,
666 UrbRequest->TransferBufferLength);
667
668 Mdl = IoAllocateMdl(UrbRequest->TransferBuffer,
669 UrbRequest->TransferBufferLength,
670 FALSE,
671 FALSE,
672 NULL);
673
674 if (!Mdl)
675 {
676 DPRINT1("USBPORT_ValidateTransferParametersURB: Not allocated Mdl\n");
678 }
679
681
682 UrbRequest->TransferBufferMDL = Mdl;
683 Urb->UrbHeader.UsbdFlags |= USBD_FLAG_ALLOCATED_MDL;
684
685 DPRINT_URB("USBPORT_ValidateTransferParametersURB: Mdl - %p\n", Mdl);
686 }
687
688 return STATUS_SUCCESS;
689}
690
692NTAPI
694 IN PIRP Irp,
695 IN PURB Urb,
696 IN BOOLEAN IsControlTransfer,
697 IN BOOLEAN IsNullTransfer)
698{
699 struct _URB_CONTROL_TRANSFER *UrbRequest;
702 USBD_STATUS USBDStatus;
703
704 UrbRequest = &Urb->UrbControlTransfer;
705
706 if (UrbRequest->UrbLink)
707 {
710
711 DPRINT1("USBPORT_ValidateURB: Not valid parameter\n");
712
714 return Status;
715 }
716
717 DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
718
719 if (IsControlTransfer)
720 {
722 UrbRequest->PipeHandle = &DeviceHandle->PipeHandle;
723 }
724
726 {
727 if (UrbRequest->TransferBufferLength > 0x1000)
728 {
731
732 DPRINT1("USBPORT_ValidateURB: Not valid parameter\n");
733
735 return Status;
736 }
737
738 if (Urb->UrbHeader.Function == URB_FUNCTION_CONTROL_TRANSFER)
739 {
740 UrbRequest->PipeHandle = &DeviceHandle->PipeHandle;
741 }
742 }
743
745 {
748
749 DPRINT1("USBPORT_ValidateURB: Not valid pipe handle\n");
750
752 return Status;
753 }
754
755 UrbRequest->hca.Reserved8[0] = NULL; // Transfer
756
757 if (IsNullTransfer)
758 {
759 UrbRequest->TransferBuffer = 0;
760 UrbRequest->TransferBufferMDL = NULL;
761 UrbRequest->TransferBufferLength = 0;
762 }
763 else
764 {
766
767 if (!NT_SUCCESS(Status))
768 {
769 return Status;
770 }
771 }
772
773 USBDStatus = USBPORT_AllocateTransfer(FdoDevice,
774 Urb,
776 Irp,
777 NULL);
778
779 Status = USBPORT_USBDStatusToNtStatus(Urb, USBDStatus);
780
781 if (!NT_SUCCESS(Status))
782 {
783 DPRINT1("USBPORT_ValidateURB: Not allocated transfer\n");
784 }
785
786 return Status;
787}
788
790NTAPI
792 IN PIRP Irp,
793 IN PURB Urb)
794{
796 PDEVICE_OBJECT FdoDevice;
801
802 ASSERT(Urb);
803
804 PdoExtension = PdoDevice->DeviceExtension;
805 FdoDevice = PdoExtension->FdoDevice;
806 FdoExtension = FdoDevice->DeviceExtension;
807
808 Urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
809 Urb->UrbHeader.UsbdFlags = 0;
810
811 Function = Urb->UrbHeader.Function;
812
814 {
817
818 DPRINT1("USBPORT_HandleSubmitURB: Unknown URB function - %x !!!\n",
819 Function);
820
821 return Status;
822 }
823
825 {
826 DPRINT1("USBPORT_HandleSubmitURB: Bad Request\n");
827
829
830 Irp->IoStatus.Status = STATUS_PENDING;
832 IoCsqInsertIrp(&FdoExtension->BadRequestIoCsq, Irp, NULL);
833
834 return STATUS_PENDING;
835 }
836
837 DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
838
839 if (!DeviceHandle)
840 {
841 DeviceHandle = &PdoExtension->DeviceHandle;
842 Urb->UrbHeader.UsbdDeviceHandle = DeviceHandle;
843 }
844
847 {
848 DPRINT1("USBPORT_HandleSubmitURB: Not valid device handle\n");
849
850 Irp->IoStatus.Status = STATUS_PENDING;
852 IoCsqInsertIrp(&FdoExtension->BadRequestIoCsq, Irp, NULL);
853
854 return STATUS_PENDING;
855 }
856
857 InterlockedIncrement(&DeviceHandle->DeviceHandleLock);
858
859 DPRINT_URB("USBPORT_HandleSubmitURB: Function - 0x%02X, DeviceHandle - %p\n",
860 Function,
861 Urb->UrbHeader.UsbdDeviceHandle);
862
863 switch (Function)
864 {
866 DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_ISOCH_TRANSFER UNIMPLEMENTED. FIXME. \n");
867 break;
868
871 Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, FALSE, FALSE);
872
873 if (!NT_SUCCESS(Status))
874 {
875 DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
876 break;
877 }
878
880 break;
881
890 Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
891
892 if (!NT_SUCCESS(Status))
893 {
894 DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
895 break;
896 }
897
899 break;
900
907 Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
908
909 if (!NT_SUCCESS(Status))
910 {
911 DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
912 break;
913 }
914
916 break;
917
918 case URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR:
919 DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR (0x2A) NOT_SUPPORTED\n");
922
927 Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
928
929 if (!NT_SUCCESS(Status))
930 {
931 DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
932 break;
933 }
934
936 break;
937
940 Irp,
941 Urb);
942 break;
943
946 Irp,
947 Urb);
948 break;
949
951 Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, FALSE);
952
953 if (!NT_SUCCESS(Status))
954 {
955 DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
956 break;
957 }
958
960 break;
961
963 DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_GET_INTERFACE (0x27) NOT_SUPPORTED\n");
966
969 Irp,
970 Urb);
971 break;
972
973 case URB_FUNCTION_SYNC_RESET_PIPE:
975 Irp,
976 Urb);
977 break;
978
979 case URB_FUNCTION_SYNC_CLEAR_STALL:
981 Irp,
982 Urb);
983 break;
984
987 Irp,
988 Urb);
989 break;
990
998 Status = USBPORT_ValidateURB(FdoDevice, Irp, Urb, TRUE, TRUE);
999
1000 if (!NT_SUCCESS(Status))
1001 {
1002 DPRINT1("USBPORT_HandleSubmitURB: Not valid URB\n");
1003 break;
1004 }
1005
1007 break;
1008
1011 Irp,
1012 Urb);
1013 break;
1014
1016 DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL (0x03) NOT_SUPPORTED\n");
1018
1020 DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL (0x04) NOT_SUPPORTED\n");
1022
1024 DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_GET_FRAME_LENGTH (0x05) NOT_SUPPORTED\n");
1026
1028 DPRINT1("USBPORT_HandleSubmitURB: URB_FUNCTION_SET_FRAME_LENGTH (0x06) NOT_SUPPORTED\n");
1030
1031 default:
1032 DPRINT1("USBPORT_HandleSubmitURB: Unknown URB Function - %x\n",
1033 Function);
1034 //URB_FUNCTION_RESERVED_0X0016
1035 //URB_FUNCTION_RESERVE_0X001D
1036 //URB_FUNCTION_RESERVE_0X002B
1037 //URB_FUNCTION_RESERVE_0X002C
1038 //URB_FUNCTION_RESERVE_0X002D
1039 //URB_FUNCTION_RESERVE_0X002E
1040 //URB_FUNCTION_RESERVE_0X002F
1041 break;
1042 }
1043
1044 if (Status == STATUS_PENDING)
1045 {
1046 return Status;
1047 }
1048
1049 if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_ALLOCATED_TRANSFER)
1050 {
1051 PUSBPORT_TRANSFER Transfer;
1052
1053 Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
1054 Urb->UrbControlTransfer.hca.Reserved8[0] = NULL;
1055 Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_TRANSFER;
1057 }
1058
1059 InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
1060
1061 Irp->IoStatus.Status = Status;
1063
1064 return Status;
1065}
unsigned char BOOLEAN
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
_In_ PIRP Irp
Definition: csq.h:116
NTKERNELAPI VOID NTAPI IoCsqInsertIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
Insert an IRP into the CSQ.
Definition: csq.c:177
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
#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
switch(r->id)
Definition: btrfs.c:3046
@ PdoExtension
Definition: precomp.h:49
@ FdoExtension
Definition: precomp.h:48
VOID NTAPI USBPORT_DumpingSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket)
Definition: debug.c:212
VOID NTAPI USBPORT_DumpingURB(IN PURB Urb)
Definition: debug.c:224
BOOLEAN NTAPI USBPORT_ValidateDeviceHandle(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_DEVICE_HANDLE DeviceHandle)
Definition: device.c:801
NTSTATUS NTAPI USBPORT_HandleSelectConfiguration(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: device.c:574
NTSTATUS NTAPI USBPORT_HandleSelectInterface(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: device.c:1486
NTSTATUS NTAPI USBPORT_SendSetupPacket(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PDEVICE_OBJECT FdoDevice, IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, IN PVOID Buffer, IN ULONG Length, IN OUT PULONG TransferedLen, IN OUT PUSBD_STATUS pUSBDStatus)
Definition: device.c:15
VOID NTAPI USBPORT_AbortEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PIRP Irp)
Definition: queue.c:1354
VOID NTAPI USBPORT_QueueTransferUrb(IN PURB Urb)
Definition: queue.c:1085
BOOLEAN NTAPI USBPORT_ValidatePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:469
VOID NTAPI USBPORT_SetEndpointState(IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
Definition: endpoint.c:363
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define IoAllocateMdl
Definition: fxmdl.h:88
Status
Definition: gdiplustypes.h:25
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
IoMarkIrpPending(Irp)
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:424
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define IoCompleteRequest
Definition: irp.c:1240
unsigned short USHORT
Definition: pedump.c:61
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PMDL TransferBufferMDL
Definition: usb.h:472
struct _URB * UrbLink
Definition: usb.h:473
USBD_PIPE_HANDLE PipeHandle
Definition: usb.h:468
ULONG TransferFlags
Definition: usb.h:469
struct _URB_HCD_AREA hca
Definition: usb.h:474
ULONG TransferBufferLength
Definition: usb.h:470
PVOID TransferBuffer
Definition: usb.h:471
Definition: usb.h:529
KIRQL EndpointOldIrql
Definition: usbport.h:216
LIST_ENTRY TransferList
Definition: usbport.h:228
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:215
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:211
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI USBPORT_HandleVendorOrClass(IN PIRP Irp, IN PURB Urb)
Definition: urb.c:479
NTSTATUS NTAPI USBPORT_HandleGetCurrentFrame(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:45
NTSTATUS NTAPI USBPORT_ValidateTransferParametersURB(IN PURB Urb)
Definition: urb.c:633
NTSTATUS NTAPI USBPORT_ClearStall(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:177
NTSTATUS NTAPI USBPORT_ResetPipe(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:114
NTSTATUS NTAPI USBPORT_AbortPipe(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:71
NTSTATUS NTAPI USBPORT_SyncResetPipeAndClearStall(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:224
NTSTATUS NTAPI USBPORT_HandleGetStatus(IN PIRP Irp, IN PURB Urb)
Definition: urb.c:412
NTSTATUS NTAPI USBPORT_HandleGetSetDescriptor(IN PIRP Irp, IN PURB Urb)
Definition: urb.c:560
NTSTATUS NTAPI USBPORT_HandleSubmitURB(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp, IN PURB Urb)
Definition: urb.c:791
NTSTATUS NTAPI USBPORT_ValidateURB(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PURB Urb, IN BOOLEAN IsControlTransfer, IN BOOLEAN IsNullTransfer)
Definition: urb.c:693
NTSTATUS NTAPI USBPORT_HandleDataTransfers(IN PURB Urb)
Definition: urb.c:384
NTSTATUS NTAPI USBPORT_HandleGetConfiguration(IN PURB Urb)
Definition: urb.c:18
NTSTATUS NTAPI USBPORT_HandleSetOrClearFeature(IN PURB Urb)
Definition: urb.c:307
#define USB_REQUEST_GET_STATUS
Definition: usb100.h:78
#define BMREQUEST_TO_INTERFACE
Definition: usb100.h:39
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38
#define BMREQUEST_VENDOR
Definition: usb100.h:36
#define USB_REQUEST_GET_CONFIGURATION
Definition: usb100.h:84
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb100.h:82
#define USB_REQUEST_SET_DESCRIPTOR
Definition: usb100.h:83
#define BMREQUEST_CLASS
Definition: usb100.h:35
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define USB_REQUEST_SET_FEATURE
Definition: usb100.h:80
#define BMREQUEST_HOST_TO_DEVICE
Definition: usb100.h:31
#define BMREQUEST_TO_ENDPOINT
Definition: usb100.h:40
#define BMREQUEST_STANDARD
Definition: usb100.h:34
#define USB_REQUEST_CLEAR_FEATURE
Definition: usb100.h:79
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
#define URB_FUNCTION_CLASS_INTERFACE
Definition: usb.h:113
#define URB_FUNCTION_GET_FRAME_LENGTH
Definition: usb.h:91
#define USBD_STATUS_DEVICE_GONE
Definition: usb.h:210
#define URB_FUNCTION_SELECT_INTERFACE
Definition: usb.h:87
#define URB_FUNCTION_ABORT_PIPE
Definition: usb.h:88
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
#define URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE
Definition: usb.h:102
#define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT
Definition: usb.h:123
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define URB_FUNCTION_SET_FEATURE_TO_INTERFACE
Definition: usb.h:100
#define URB_FUNCTION_VENDOR_ENDPOINT
Definition: usb.h:111
#define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE
Definition: usb.h:98
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define URB_FUNCTION_CONTROL_TRANSFER
Definition: usb.h:94
#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
Definition: usb.h:107
#define USBD_STATUS_NOT_SUPPORTED
Definition: usb.h:202
#define URB_FUNCTION_VENDOR_DEVICE
Definition: usb.h:109
#define URB_FUNCTION_SET_FEATURE_TO_OTHER
Definition: usb.h:121
#define URB_FUNCTION_GET_CURRENT_FRAME_NUMBER
Definition: usb.h:93
#define URB_FUNCTION_SELECT_CONFIGURATION
Definition: usb.h:86
#define URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL
Definition: usb.h:90
#define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT
Definition: usb.h:101
#define USBD_STATUS_INVALID_PARAMETER
Definition: usb.h:192
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE
Definition: usb.h:126
#define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT
Definition: usb.h:104
#define URB_FUNCTION_CLASS_DEVICE
Definition: usb.h:112
#define URB_FUNCTION_SET_FRAME_LENGTH
Definition: usb.h:92
#define URB_FUNCTION_SET_FEATURE_TO_DEVICE
Definition: usb.h:99
#define URB_FUNCTION_GET_STATUS_FROM_INTERFACE
Definition: usb.h:106
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT
Definition: usb.h:122
#define URB_FUNCTION_CLASS_OTHER
Definition: usb.h:117
#define URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL
Definition: usb.h:89
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95
#define URB_FUNCTION_GET_STATUS_FROM_OTHER
Definition: usb.h:119
#define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE
Definition: usb.h:127
#define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
Definition: usb.h:116
LONG USBD_STATUS
Definition: usb.h:165
#define URB_FUNCTION_GET_CONFIGURATION
Definition: usb.h:124
#define URB_FUNCTION_CLEAR_FEATURE_TO_OTHER
Definition: usb.h:120
#define USBD_STATUS_ERROR_BUSY
Definition: usb.h:193
#define URB_FUNCTION_CLASS_ENDPOINT
Definition: usb.h:114
#define USBD_DEFAULT_PIPE_TRANSFER
Definition: usb.h:156
#define USBD_STATUS_INVALID_URB_FUNCTION
Definition: usb.h:191
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
#define URB_FUNCTION_VENDOR_INTERFACE
Definition: usb.h:110
#define URB_FUNCTION_VENDOR_OTHER
Definition: usb.h:118
#define USBD_TRANSFER_DIRECTION_FLAG(flags)
Definition: usb.h:157
#define URB_FUNCTION_GET_INTERFACE
Definition: usb.h:125
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
#define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE
Definition: usb.h:103
#define URB_FUNCTION_ISOCH_TRANSFER
Definition: usb.h:96
#define DPRINT_URB(...)
Definition: usbdebug.h:145
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define USBPORT_ENDPOINT_RUN
Definition: usbmport.h:20
#define USBPORT_ENDPOINT_PAUSED
Definition: usbmport.h:14
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
Definition: usbmport.h:7
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
#define USBPORT_TRANSFER_DIRECTION_OUT
Definition: usbmport.h:649
USBD_STATUS NTAPI USBPORT_AllocateTransfer(IN PDEVICE_OBJECT FdoDevice, IN PURB Urb, IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PIRP Irp, IN PRKEVENT Event)
Definition: usbport.c:2543
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
#define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE
Definition: usbport.h:127
#define USB_PORT_TAG
Definition: usbport.h:44
#define USBD_FLAG_ALLOCATED_TRANSFER
Definition: usbport.h:123
#define USBPORT_TMFLAG_RH_SUSPENDED
Definition: usbport.h:96
#define URB_FUNCTION_MAX
Definition: usbport.h:45
#define USBD_FLAG_ALLOCATED_MDL
Definition: usbport.h:121
struct _USBPORT_PIPE_HANDLE * PUSBPORT_PIPE_HANDLE
#define ENDPOINT_FLAG_QUEUENE_EMPTY
Definition: usbport.h:114
#define USBD_FLAG_NOT_ISO_TRANSFER
Definition: usbport.h:122
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_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
#define IO_NO_INCREMENT
Definition: iotypes.h:598
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778